[Python-ideas] Enhancing dict.values

Ethan Furman ethan at stoneleaf.us
Fri May 27 12:12:57 EDT 2016


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.

> 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.

--
~Ethan~


More information about the Python-ideas mailing list