On Fri, May 1, 2009 at 4:25 PM, Dave Angel wrote:
> The problem is in it2, which is initialized only once. Thus the second time
> you're going through the c2 loop, it doesn't have any more values.
>
> If you need the indirection provided by those it1 and it2, you need to
> postpone the function
ops...@batnet.com wrote:
I'm a little baffled by the inconsistency here. Anyone have any
explanations?
def gen():
... yield 'a'
... yield 'b'
... yield 'c'
...
[c1 + c2 for c1 in gen() for c2 in gen()]
['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
D'oh! Many thanks for the explanation; I should have seen that myself.
--
http://mail.python.org/mailman/listinfo/python-list
ops...@batnet.com wrote:
it1 = gen()
it2 = gen()
list(c1 + c2 for c1 in it1 for c2 in it2)
> ['aa', 'ab', 'ac']
>
> Why does this last list only have three elements instead of nine?
First time through the c1 in it1 loop you use up all of the it2 values.
Second and third times thro
On Fri, 01 May 2009 04:58:16 -0700, opstad wrote:
> I'm a little baffled by the inconsistency here. Anyone have any
> explanations?
>
def gen():
> ... yield 'a'
> ... yield 'b'
> ... yield 'c'
> ...
[c1 + c2 for c1 in gen() for c2 in gen()]
> ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', '
ops...@batnet.com a écrit :
I'm a little baffled by the inconsistency here. Anyone have any
explanations?
def gen():
... yield 'a'
... yield 'b'
... yield 'c'
...
[c1 + c2 for c1 in gen() for c2 in gen()]
['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
I'm a little baffled by the inconsistency here. Anyone have any
explanations?
>>> def gen():
... yield 'a'
... yield 'b'
... yield 'c'
...
>>> [c1 + c2 for c1 in gen() for c2 in gen()]
['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
>>> list(c1 + c2 for c1 in gen() for c2 in gen())
[