[Python-ideas] Enhancing dict.values

M.-A. Lemburg mal at egenix.com
Fri May 27 12:52:15 EDT 2016


On 27.05.2016 18:12, Ethan Furman wrote:
> On 05/27/2016 08:02 AM, Michael Selik wrote:
>> On Thu, May 26, 2016 at 11:39 PM Steven D'Aprano wrote:
>>> On Thu, May 26, 2016 at 11:28:25PM +0100, Nathan Schneider wrote:
> 
>>>> Instead of special syntax, what if dict.values() returned a tuple
>>>> when given keys as arguments:
>>>>
>>>>    partner_id, product_id, ship_to, product_ids = my_dict.values(
>>>>            'partner_id', 'product_id', 'ship_to', 'product_ids')
>>>
>>> I like this idea. I think it beats the status quo:
>>
>> Isn't this the status quo?
>>      a, b, c = [mapping[k] for k in ('a', 'b', 'c')]
> 
> Yes.

Uhm, what about...

from operator import itemgetter

a, b, c = itemgetter('a', 'b', 'c')(mapping)

(itemgetter is not the best name, but it does get the job done)

>> That was already someone's argument that a special dict unpacking syntax
>> is unnecessary.
> 
> It looks really cool at first blush, but when substituting real names in
> for the place-holders a, b, and c it gets ugly fast.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, May 27 2016)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   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
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Python-ideas mailing list