Python Generators

sturlamolden sturlamolden at yahoo.no
Sat Mar 15 17:26:05 EDT 2008


On 15 Mar, 21:35, mpc <mcoh... at gmail.com> wrote:


> generator embedded in the argument only once. Can anyone explain while
> the generator will not re-initiate, and suggest a simple fix?


I am not sure what you are trying to do, but it seems a bit confused.


>>> def concat(seq):
	for s in seq: yield s

>>> seq = xrange(3)

>>> for n in xrange(5):
	h = concat(s for s in seq)
	for i in h: print i,n


0 0
1 0
2 0
0 1
1 1
2 1
0 2
1 2
2 2
0 3
1 3
2 3
0 4
1 4
2 4

Generators work they way they should. Even when one is used as
argument for another.











More information about the Python-list mailing list