[Python-ideas] Generator unpacking

Sven R. Kunze srkunze at mail.de
Mon Feb 15 17:11:24 EST 2016


On 15.02.2016 19:00, Jonathan Goble wrote:
> On Mon, Feb 15, 2016 at 12:53 PM, Sven R. Kunze <srkunze at mail.de> wrote:
>> On 15.02.2016 18:39, Ethan Furman wrote:
>>> I /think/ I've used that trick to confirm an iterable was empty; I /know/
>>> I've used
>>>
>>> [some_var] = some_var
>>
>> Is that an unknown Python idiom?
>>
>> It looks short but still insane.
> It's actually a useful way to quickly unpack nested lists and tuples.
> Here's a quick example:
>
> [snip]

I am aware of (nested) unpacking in general. :)


The use-case of checking if a list is has only a single element and to 
unpack it in a single statement has simply never occurred to me.


Best,
Sven


More information about the Python-ideas mailing list