[Python-ideas] Unpack of sequences

MRAB python at mrabarnett.plus.com
Wed Aug 29 21:47:52 CEST 2012

On 29/08/2012 20:24, Alexander Belopolsky wrote:
> On Wed, Aug 29, 2012 at 2:21 PM, Guido van Rossum <guido at python.org> wrote:
>>> {a, b, c} = m
>> But {a, b, c} is already a set. I'd expect set-like semantics, perhaps
>> assigning the keys of a 3-element set in arbitrary order to the
>> variables a, b and c.
> I considered this before posting and I think the potential for such
> confusion is rather low.  We already allow [a,b,c] = and (a,b,c) =
> even though tuples are supposed to be immutable and (a,b,c) = may look
> like a syntax error to someone unfamiliar with unpacking.  I don't see
> much of a problem with having the same syntactic elements have
> different meaning when they appear as in an assignment target.
If you did want to unpack a set, that would be:

(a, b, c) = m

{...} are used for both dicts and sets, after all.

I must admit it's starting to look a bit better to me.

More information about the Python-ideas mailing list