[Python-ideas] Generator unpacking
Chris Angelico
rosuav at gmail.com
Wed Feb 17 08:58:08 EST 2016
On Wed, Feb 17, 2016 at 4:54 AM, Georg Brandl <g.brandl at gmx.net> wrote:
>> Another aspect, I came to think of is the following asymmetry:
>>
>> a, b, c, d = mylist4 # works
>> a, b, c = mylist3 # also works
>> a, b = mylist2 # works too
>> [a] = mylist1 # special case?
>
> a, = mylist1
>
> actually. Same "special case" as with 1-element tuples.
The one-target case is actually available to everything else; the only
difference is that the trailing comma is mandatory, not optional:
>>> a,b,c, = range(3)
Which is, again, the same as with tuples.
ChrisA
More information about the Python-ideas
mailing list