def preorder_iter(self, filter_fn=None):
        """ From DendroPy
        Preorder traversal of self and its child_nodes.  Returns self
        and all descendants such that a node is returned before its
        child_nodes (and their child_nodes). Filtered by filter_fn: node is
        only returned if no filter_fn is given or if filter_fn returns
        True.
        """
        stack = [self]
        while stack:
            node = stack.pop()
            if filter_fn is None or filter_fn(node):
                yield node
            stack.extend([i for i in reversed(node._children)])
def preorder_iter ( self , filter_fn = None ) : stack = [ self ] while stack : node = stack . pop ( ) if filter_fn is None or filter_fn ( node ) : yield node stack . extend ( [ i for i in reversed ( node . _children ) ] )
From DendroPy
        Preorder traversal of self and its child_nodes.  Returns self
        and all descendants such that a node is returned before its
        child_nodes (and their child_nodes). Filtered by filter_fn: node is
        only returned if no filter_fn is given or if filter_fn returns
        True.