2012/8/29 M.-A. Lemburg <span dir="ltr"><<a href="mailto:mal@egenix.com" target="_blank">mal@egenix.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">Cesare Di Mauro wrote:<br>
> 2012/8/29 Mike Graham <<a href="mailto:mikegraham@gmail.com">mikegraham@gmail.com</a>><br>
><br>
>> On Wed, Aug 29, 2012 at 11:45 AM, Masklinn <<a href="mailto:masklinn@masklinn.net">masklinn@masklinn.net</a>> wrote:<br>
>>> On 2012-08-29, at 17:03 , Guido van Rossum wrote:<br>
>>>><br>
>>>> Also of course assignment has no equivalent to keyword parameters<br>
>>><br>
>>> I've always thought it would be a rather neat way to unpack<br>
>>> dictionaries, instead of doing it by hand or abusing `itemgetter` to get<br>
>>> values in a known order.<br>
>><br>
>> Do you have a suggestion of a nice syntax for a thing to unpack<br>
>> mappings (or to unpack things by attributes)?<br>
>><br>
>> Mike<br>
>><br>
><br>
> a: x, b: y, c: z = {'a': 'x', 'b': 'y', 'c': 'z'}<br>
<br>
</div></div> </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Would this assign 'a' to a or just use a as key for the lookup ?<br>
If the former, where would you take the lookup order from ?<br>
If the latter, what about keys that are not valid Python identifiers ?<br>
<br>
</blockquote><div><br></div><div>The latter. But we already have problems with Python identifiers:</div><div><br></div><div>>>> def f(**Keywords): pass</div><div>>>> f(**{1 : 'BAD!'})<br>Traceback (most recent call last):<br>
  File "<pyshell#2>", line 1, in <module><br>    f(**{1 : 'BAD!'})<br>TypeError: f() keywords must be strings</div><div> </div><div>It wasn't a feature blocker...</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
mxTools has a function extract() to extract values from a mapping<br>
or sequence object:<br>
<br>
extract(object,indices[,defaults])<br>
  Builds a list with entries object[index] for each index in the sequence indices.<br>
  (see <a href="http://www.egenix.com/products/python/mxBase/mxTools/doc/" target="_blank">http://www.egenix.com/products/python/mxBase/mxTools/doc/</a>)<br>
<br>
>>> mx.Tools.extract(d, ('a', 'b', 'c'))<br>
['x', 'y', 'z']<br>
<br>
IMO, that's a much cleaner way to express what you'd like Python<br>
to do.<br>
<br>
--<br> Marc-Andre Lemburg<br></blockquote><div> </div><div>Yes, may be an extract method for mappings will be finer.</div><div><br></div><div>Cesare</div>