[Python-ideas] Generator unpacking
Ethan Furman
ethan at stoneleaf.us
Wed Feb 17 11:26:29 EST 2016
On 02/17/2016 05:58 AM, Chris Angelico wrote:
> 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.
Did you mean the trailing comma is necessary in the one-tuple case?
--> a, b, c = range(3)
--> a
0
--> b
1
--> c
2
--> a = range(1)
--> a
[0]
--> a, = range(1)
--> a
0
--
~Ethan~
More information about the Python-ideas
mailing list