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

Dave Kuhlman dkuhlman at rexx.com
Fri Jul 13 01:26:08 CEST 2007

I find iterators and generators fascinating.  So, in order to try
to understand them better myself, I've written up some notes.  I'm
hoping that these notes might help someone new to the generators
and iterators in Python.  You can find it here:


I'll appreciate any comments and suggestions that might help me
improve it.

Please pass the above link along to anyone you think it might help.

And, I have a question -- If you look at the example of the
iterative (non-recursive) generator (the Doubler class), you will
see that it walks a list, not a tree.  That's because I was *not*
able to figure out how to implement a non-recursive tree walk

I found examples showing non-recursive/iterative solutions to how
to walk a *binary* tree.  Those examples are at:

    Lib/test/test_generator.py   # in the Python distribution

But, I could not find a example that shows a non-recursive way to
walk a tree in which each node has an arbitrary number of children.

Alas, I could not write that non-recursive tree walk.  The recusive
walk is easy and clean.  So, maybe I should not worry about the
non-recursive approach.  Still, it really bothers me that I could
not do it.

So, if you know where there are some examples, that would help me
improve my notes on iterators and generators, please give me a


Dave Kuhlman

More information about the Tutor mailing list