[Python-ideas] Another attempt at a sum() alternative: the concatenation protocol
Oscar Benjamin
oscar.j.benjamin at gmail.com
Tue Jul 16 17:22:06 CEST 2013
On 16 July 2013 15:48, Masklinn <masklinn at masklinn.net> wrote:
>>> You could wait for PEP 448, which will let you use [*sublist for
>>> sublist in list_to_be_flattened].
>>
>> Well that does look good. How exactly does it unroll? Does the *
>> translate as yield from but without the weird comprehension turning
>> into a generator function behaviour?
>
> For a listcomp, surely it translates into a .extend of the accumulator?
So
[a for b in c]
is
for b in c:
result.append(a)
and
[*a for b in c]
is
for b in c:
result.extend(a)
Set and dict comps presumably use .update. And the generator expression
(*a for b in c)
becomes
for b in c:
for x in a:
yield x
or is it actually (this is not equivalent):
for b in c:
yield from a
Currently,
((yield from a) for b in c)
becomes:
for b in c:
yield (yield from a)
which is perhaps less useful (because of the additional yielded None values).
Oscar
Oscar
More information about the Python-ideas
mailing list