def ipostorder(self):
        '''Depth-first post-order iteration of tree nodes'''
        children = [self, ]
        seen = set()
        while children:
            cur_node = children[-1]
            if cur_node not in seen:
                seen.add(cur_node)
                children.extend(reversed(cur_node.children))
            else:
                children.pop()
                yield cur_node
Depth-first post-order iteration of tree nodes