[Python-ideas] Unpack of sequences

M.-A. Lemburg mal at egenix.com
Wed Aug 29 18:41:02 CEST 2012

Cesare Di Mauro wrote:
> 2012/8/29 Mike Graham <mikegraham at gmail.com>
>> On Wed, Aug 29, 2012 at 11:45 AM, Masklinn <masklinn at masklinn.net> wrote:
>>> On 2012-08-29, at 17:03 , Guido van Rossum wrote:
>>>> Also of course assignment has no equivalent to keyword parameters
>>> I've always thought it would be a rather neat way to unpack
>>> dictionaries, instead of doing it by hand or abusing `itemgetter` to get
>>> values in a known order.
>> Do you have a suggestion of a nice syntax for a thing to unpack
>> mappings (or to unpack things by attributes)?
>> Mike
> a: x, b: y, c: z = {'a': 'x', 'b': 'y', 'c': 'z'}

Would this assign 'a' to a or just use a as key for the lookup ?
If the former, where would you take the lookup order from ?
If the latter, what about keys that are not valid Python identifiers ?

mxTools has a function extract() to extract values from a mapping
or sequence object:

  Builds a list with entries object[index] for each index in the sequence indices.
  (see http://www.egenix.com/products/python/mxBase/mxTools/doc/)

>>> mx.Tools.extract(d, ('a', 'b', 'c'))
['x', 'y', 'z']

IMO, that's a much cleaner way to express what you'd like Python
to do.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Aug 29 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2012-10-23: Python Meeting Duesseldorf ...                 55 days to go
2012-08-28: Released mxODBC 3.2.0 ...             http://egenix.com/go31
2012-08-20: Released mxODBC.Connect 2.0.0 ...     http://egenix.com/go30

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-ideas mailing list