Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Scott David Daniels
Ken Pu wrote: Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) ... print list(islice(itlist[0], 5)

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Steven D'Aprano
On Fri, 16 Jan 2009 02:51:43 -0500, Ken Pu wrote: > Hi, below is the code I thought should create two generates, it[0] = > 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the > same!!! [...] > I see what Python is doing -- lazy evaluation doesn't evaluate (x+(i*10) > for x in cou

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread alex23
James Stroud wrote: > I'm going to get flamed > pretty hard for this, but it doesn't seem to be the intuitive behavior > to me either. Given this is the second time this issue has come up today, I'd have to agree with you. -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic
itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) oops, that would be itlist[i] = (x+(i*10) for i,s in [(i,count())] for x in s) or equivalent, kind of ugly anyway. -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic
The minimal correction, I guess, is to write itlist[i] = (x+(i*10) for i in [i] for x in count()) instead of itlist[i] = (x+(i*10) for x in count()) although itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) will better mimic generalizations in the sense that the "minimal cor

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Michael Hartl
James Stroud schrieb: Ken Pu wrote: Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) print "what

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread James Stroud
Ken Pu wrote: Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) print "what's in the bags:" print

lazy evaluation is sometimes too lazy... help please.

2009-01-15 Thread Ken Pu
Hi, below is the code I thought should create two generates, it[0] = 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the same!!! from itertools import * itlist = [0,0] for i in range(2): itlist[i] = (x+(i*10) for x in count()) print "what's in the bags:" print list(islice(itli