PEP 255: Simple Generators

Neil Schemenauer nas at python.ca
Mon Jun 18 21:08:07 EDT 2001


Russell E. Owen wrote:
> * A generator looks like a function until you find the "yield" statement 
> inside. I think this will make the code much harder to read. One keyword 
> buried anywhere in a function totally changes its behavior.

Not really.  For example, the functions

    def f1(n):
        for i in range(n):
            yeild i

    def f2(n):
        return iter(range(n))

do pretty much the same thing.  "yeild" is just a handy way of
creating iterators.
    
  Neil




More information about the Python-list mailing list