from functools import reduce


def extract_words(tree, word_types_to_return):
    """
    Extracts words of certain types from a parsed tree. Types to return is list or tuple of types
    """
    try:
        tree.node
    except AttributeError:
        if tree[1] in word_types_to_return:
            return [tree[0]]
        else:
            return []
    else:
        return reduce(lambda a, b: a + b, [extract_words(child, word_types_to_return) for child in tree])