[Tutor] Here is newbie doc on how to implement generators

Kent Johnson kent37 at tds.net
Mon Jul 16 23:39:14 CEST 2007


John Fouhy wrote:
> def walkTree(tree):
>     # stack to hold nodes as we walk through
>     stack = []
>     stack.append(tree)
> 
>     while stack:
>         value, children = stack.pop()
>         for child in reversed(children):  # reverse children to get
> the right order.
>             stack.append(child)

FWIW this could be written as
   stack.extend(reversed(children))

Kent


More information about the Tutor mailing list