[Python-3000] PEP 3132: Extended Iterable Unpacking (original) (raw)

Simon Percivall percivall at gmail.com
Fri May 4 13:05:45 CEST 2007


On 4 maj 2007, at 06.13, Greg Ewing wrote:

Simon Percivall wrote:

if the proposal is constrained to only allowing the *name at the end, wouldn't a more useful behavior be to not exhaust the iterator, making it similar to: > it = iter(range(10)) > a = next(it) > b = it or would this be too surprising? It would surprise the heck out of me when I started with something that wasn't an iterator and ended up with b being something that I could only iterate and couldn't index.

Yes, that would be surprising.

This was more in the way of returning the type that was given: if you start with a list you end up with a list in "b", if you start with an iterator you end up with an iterator. This would enable stuff like using this with itertools.count and other iterators that represent infinite sequences.

Also, I'm not intending to argue this, but exhausting the iterator is not exactly like *args in argument lists, because the iterator isn't the name being starred. It's more like the formal parameter of a function, when the receiver of the iterator is starred, but the iterator is not. The iterator isn't automatically exhausted in those cases.

//Simon



More information about the Python-3000 mailing list