def findElements(element, predicate):
    """
    Recursively collect all elements in an L{HTMLElement} tree that
    match the optional predicate.
    """
    if predicate(element):
        return [element]
    elif isLeaf(element):
        return []

    return [result
            for child in element.children
            for result in findElements(child, predicate)]

    Recursively collect all elements in an L{HTMLElement} tree that
    match the optional predicate.
    
stackoverflow/venv/lib/python3.6/site-packages/automat/_test/test_visualize.py