PEP 255: Simple Generators
Olaf Delgado Friedrichs
delgado at okeeffe-pc3.la.asu.edu
Tue Jun 19 04:46:13 EDT 2001
On Tue, 19 Jun 2001 18:21:14 +1200, Greg Ewing <see at my.signature> wrote:
>Something is bothering me about this. In fact,
>it's bothering me a LOT. In the following, will
>f() work as a generator-function:
>
> def f():
> for i in range(5):
> g(i)
>
> def g(i):
> for j in range(10):
> yield i,j
>
>If I understand PEP255 correctly, this will *not*
>work. But it seems entirely reasonable to me that
>it *should* work. It *has* to work, otherwise how
>am I to write generators that are too complicated
>to fit into a single function?
If I understand correctly, this should work:
def f():
for i in range(5):
for x in g(i):
yield x
def g(i):
for j in range(10):
yield i,j
Olaf
More information about the Python-list
mailing list