Unpacking extension (Re: A small inconsistency in syntax?)
Bernhard Herzog
bh at intevation.de
Wed Oct 31 14:49:53 EST 2001
me at mikerobin.com (Michael Robin) writes:
> I'd think there's no reason to disallow it.
> Although in Python the comma operator creates tuples
> rather than the parens, for many it looks as if
> a,b = seq
> is just shorthand for
> (a,b) = seq
This version would not be removed. You need some kind of grouping to
support nested unpackings.
> and if it unpacks lists too (which it does)
> you may as well have the option of being
> explicit in your LHS pattern.
Why, if it doesn't make a difference at all?
a, b = t
(a, b) = t
[a, b] = t
are completely equivalent. They all generate the same bytecode and work
for all kinds of sequences with length 2.
> Also, given that lists are mutable and tuples are
> not, the list notation makes some kind of sense,
> even though you're rebinding the names in the LHS
> rather than creating a list, per se.
In my eyes the mutability of the RHS doesn't enter into it. All that
matters is that it's a sequence of the right length.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://mapit.de/
More information about the Python-list
mailing list