I am trying to yield nodes in a tree with a generator using a preorder depth first search. The parents node can have any number of children and the children are stored in a list.
I figured this code would work, but it appears that the for loop is iterating over each child without actually going into the recursive call.
def traverse_tree(t):
yield t.label, t.val
for child in t.children:
traverse_tree(child)
Does anyone know how to handle this?