revive a generator

Yingjie Lan lanyjie at yahoo.com
Thu Oct 20 09:23:50 EDT 2011


Hi,

it seems a generator expression can be used only once:

>>> g = (x*x for x in range(3))
>>> for x in g: print x
0
1
4
>>> for x in g: print x #nothing printed
>>>

Is there any way to revive g here?

Yingjie



More information about the Python-list mailing list