[Python-ideas] dictionary unpacking

Facundo Batista facundobatista at gmail.com
Tue Apr 1 15:13:35 CEST 2008


2008/3/31, Mathias Panzenböck <grosser.meister.morti at gmx.net>:

> Maybe dictionary unpacking would be a nice thing?
>
>   >>> d = {'foo': 42, 'egg': 23}
>   >>> {'foo': bar, 'egg': spam} = d
>   >>> print bar, spam
>  42 23

Bad idea.

It uncovers a lot of details for your brain to take care  when doing
that, for example:

>>> d = {'foo': 42, 'egg': 23}
>>> {'not': bar, 'egg': spam} = d
>>> print bar
???
>>> {'egg': bar, 'egg': spam} = d
>>> print bar
???

I would consider something like the following:

  bar, spam = d.multiple("foo", "egg")

with the semantics of:

  bar, spam = [d[k] for k in ("foo", "egg")]

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/



More information about the Python-ideas mailing list