[Python-ideas] Fwd: Fwd: unpacking generalisations for list comprehension
Random832
random832 at fastmail.com
Thu Oct 13 15:51:57 EDT 2016
On Thu, Oct 13, 2016, at 15:46, Random832 wrote:
> so, under a similar 'transformation', "*foo for foo in bar" likewise
> becomes "def f(): for foo in bar: yield from foo"
>
> bar = [(1, 2), (3, 4)]
> (*(1, 2), *(3, 4)) == == tuple(f())
> [*(1, 2), *(3, 4)] == == list(f())
I accidentally hit ctrl-enter while copying and pasting, causing my
message to go out while my example was less thorough than intended and
containing syntax errors. It was intended to read as follows:
..."*foo for foo in bar" likewise becomes
def f():
for foo in bar:
yield from foo
a, b = (1, 2), (3, 4)
bar = [a, b]
(*a, *b) == (1, 2, 3, 4) == tuple(f()) # tuple(*foo for foo in bar)
[*a, *b] == [1, 2, 3, 4] == list(f()) # [*foo for foo in bar]
More information about the Python-ideas
mailing list