31 Aug
2012
31 Aug
'12
7:18 a.m.
On 8/30/2012 8:17 PM, Greg Ewing wrote:
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.
dit = iter(d) a,b,d = next(dit), next(dit), next(dit) or, most efficiently a = next(dit) b = next(dit) c = next(dit) or a, b, c = [next(dit) for i in range(3)] -- Terry Jan Reedy