def ipreorder(self):
        '''Depth-first pre-order iteration of tree nodes'''
        children = deque((self, ))
        while children:
            cur_node = children.pop()
            children.extend(reversed(cur_node.children))
            yield cur_node
Depth-first pre-order iteration of tree nodes