[Python-ideas] Unpack of sequences

Mathias Panzenböck grosser.meister.morti at gmx.net
Wed Aug 29 23:12:15 CEST 2012

On 08/29/2012 08:07 PM, Alexander Belopolsky wrote:
> On Wed, Aug 29, 2012 at 1:28 PM, Guido van Rossum <guido at python.org> wrote:
>> it's probably better not to add a language feature and let users write
>> what they want.
> How can users write a solution that does not require repetition of
> variable names? Of course I can write something like
> a, b, c = [m.get(x) for x in ('a', 'b', 'c')]
> but when I have more and longer names, this gets tedious.
> As far as syntax goes, I also find a, b, c = **m somewhat unintuitive.
>   I would prefer
> {a, b, c} = m
> and
> {a, b, c, **rest} = m.

Note: Mozilla's JavaScript 1.8 has this:

var {a, b, c} = m;

While such a feature would sometimes be handy, I understand that it is a collision with the set syntax.

>> I'd be even less sure about something syntactically similarly plausible like
>> self.a, self.b, self.c = **foo
> I don't think unpacking into attributes is as useful as unpacking into
> locals.  Object attribute lists are often available programmatically
> and it is a simple matter to supply an _update() function that can be
> used as self._update(locals()) after values have been assigned to
> locals or simply use self._update(m) directly.
> (I recall that something like {'a': x, 'b': y} = m has been suggested
> and rejected in the past.  That syntax also required explicit
> specification of the keys to be unpacked.)

More information about the Python-ideas mailing list