def _dfs_preorder(node, visited):
    """Iterate through nodes in DFS pre-order."""
    if node not in visited:
        visited.add(node)
        yield node
    if node.lo is not None:
        yield from _dfs_preorder(node.lo, visited)
    if node.hi is not None:
        yield from _dfs_preorder(node.hi, visited)
def _dfs_preorder ( node , visited ) : if node not in visited : visited . add ( node ) yield node if node . lo is not None : yield from _dfs_preorder ( node . lo , visited ) if node . hi is not None : yield from _dfs_preorder ( node . hi , visited )
Iterate through nodes in DFS pre-order.