2012/8/29 M.-A. Lemburg <mal@egenix.com>
Cesare Di Mauro wrote:
> 2012/8/29 Mike Graham <mikegraham@gmail.com>
>
>> On Wed, Aug 29, 2012 at 11:45 AM, Masklinn <masklinn@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:
extract(object,indices[,defaults])
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