[Python-ideas] Generator unpacking

Andrew Barnert abarnert at yahoo.com
Mon Feb 15 03:54:03 EST 2016


On Feb 15, 2016, at 00:50, Chris Angelico <rosuav at gmail.com> wrote:
> 
>> On Mon, Feb 15, 2016 at 6:33 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Curious about what would happen, I tried
>> 
>>>>> [] = 42
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> TypeError: 'int' object is not iterable
>> 
>> So it appears that [] = something is a cute way of asserting
>> that the rhs is iterable without consuming anything from it!
> 
> Yeah... uhh... "iter(x)" is a less cute way of asserting that it's iterable :D

With the side benefit of not also asserting that it's empty, and not possibly consuming elements. :)


More information about the Python-ideas mailing list