On Fri, Jan 9, 2009 at 10:15 PM, Justin wrote:
> However when I attempt to convert preorder() to a generator and
> iterate over the results things don't go as planned:
>
> def preorder(tree, index, path=[]):
>if index >= len(tree): return
>path = path + [tree[index]]
>yield path
>
Hello, I am new to Python and I'm having trouble with generators. I
have built a tree (and verified that it looks good, and my left() and
right() functions are correct as well), and I am able to traverse it
as I would expect:
def preorder(tree, index, path=[]):
if index >= len(tree): return