[Python-ideas] Unpacking a dict

Ethan Furman ethan at stoneleaf.us
Wed May 25 20:14:27 EDT 2016


On 05/25/2016 04:58 PM, MRAB wrote:
> On 2016-05-26 00:41, Ethan Furman wrote:

>> or, as Random pointed out
>>
>>    x, y, z = [some_dict[k] for k in ('a', 'b', 'c')]
>>
>> which has a nice symmetry to it.
>
> Could we use 'as', which is already used for renaming in imports?
>
>      a as x, b as y, c as z = some_dict

I'm okay with that.

> or, perhaps:
>
>      'a' as x, 'b' as y, 'c' as z = some_dict
>
> which would cater for keys that aren't valid as identifiers.

That probably makes more sense, especially since it's already the 
rare(r) case of needing/wanting to rename the keys.

--
~Ethan~


More information about the Python-ideas mailing list