[Python-ideas] Generator unpacking

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Feb 15 02:33:30 EST 2016


Andrew Barnert via Python-ideas wrote:
> On Feb 14, 2016, at 10:57, Georg Brandl <g.brandl at gmx.net> wrote:
 >
>> ... = ...
> 
> With the original version, where ... means "unpack 0 elements from the
> iterable and stop", it would presumably raise a TypeError("'ellipsis' object
> is not iterable").

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!

-- 
Greg



More information about the Python-ideas mailing list