Dave Abrahams writes:
list(chain( *(((x,n) for n in range(3)) for x in 'abc') ))
> [('c', 0), ('c', 1), ('c', 2), ('c', 0), ('c', 1), ('c', 2), ('c', 0), ('c',
> 1), ('c', 2)]
>
> Huh? Can anyone explain why the last result is different?
list(chain(*EXPR)) is constructing a tuple out of
Dave Abrahams wrote:
list(chain( *(((x,n) for n in range(3)) for x in 'abc') ))
> [('c', 0), ('c', 1), ('c', 2), ('c', 0), ('c', 1), ('c', 2), ('c', 0),
> [('c', 1), ('c', 2)]
>
> Huh? Can anyone explain why the last result is different?
> (This is with Python 2.6)
The *-operator is not
Please consider:
>>> from itertools import chain
>>> def enum3(x): return ((x,n) for n in range(3))
...
>>> list(enum3('a'))
[('a', 0), ('a', 1), ('a', 2)]
# Rewrite the same expression four different ways:
>>> list(chain( enum3('a'), enum3('b'), enum3('c') ))
[('a', 0), ('a', 1), ('a', 2),