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)
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
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
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
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
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
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
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