def __iter__ ( self ) : for node in chain ( * imap ( iter , self . children ) ) : yield node yield self
python iterate over immediate children
Iterate through tree leaves first
def __iter__(self):
        """
        Iterate through tree, leaves first

        following http://stackoverflow.com/questions/6914803/python-iterator-through-tree-with-list-of-children
        """
        for node in chain(*imap(iter, self.children)):
            yield node
        yield self