[Python-Dev] Extending tuple unpacking
Guido van Rossum
guido at python.org
Fri Oct 7 19:34:05 CEST 2005
On 10/7/05, Gustavo Niemeyer <gustavo at niemeyer.net> wrote:
> Not sure if this has been proposed before, but one thing
> I occasionally miss regarding tuple unpack is being able
> to do:
> first, second, *rest = something
> Also in for loops:
> for first, second, *rest in iterator:
> This seems to match the current meaning for starred
> variables in other contexts.
Someone should really write up a PEP -- this was just discussed a week
or two ago.
I personally think this is adequately handled by writing:
(first, second), rest = something[:2], something[2:]
I believe that this wish is an example of "hypergeneralization" -- an
incorrect generalization based on a misunderstanding of the underlying
Argument lists are not tuples [*] and features of argument lists
should not be confused with features of tuple unpackings.
[*] Proof: f(1) is equivalent to f(1,) even though (1) is an int but
(1,) is a tuple.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev