[Python-ideas] Unpack of sequences

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Aug 31 02:17:00 CEST 2012


Mike Graham wrote:
> That being said, `a, b, c, *_ = d` or similar is probably better than
> introducing a new way.

It's inefficient, though, because it results in iterating
over the remainder of the sequence and building a new sequence
that will never be used.

There's currently no way to spell the most efficient way of
doing this, which is simply to stop iterating and ignore the
rest of the sequence. There's also no way to unpack the
head of an infinite sequence without slicing it first.

-- 
Greg



More information about the Python-ideas mailing list