[Python-ideas] Dict(x, y) -> Dict(zip(x, y))

MRAB python at mrabarnett.plus.com
Tue Feb 16 19:34:44 EST 2016


On 2016-02-16 23:48, Ian Foote wrote:
> On 15/02/16 09:53, Andrew Barnert via Python-ideas wrote:
>
>>
>> But what about a classmethod named constructor (with or without
>> keyword-only params, depending on how long the name is):
>>
>>     dict.kv(keys=spam, values=eggs)
>>     dict.from_keys_values(spam, eggs)
>>
Going the other way it's "my_dict.items()", so perhaps 
"dict.from_items(spam, eggs)"?

>
> I would spell this dict.zip(keys, values). It brings to mind the current
> implementation, but allows for optimisation. It's also slightly less
> parenthesis heavy, which I think makes it a little more readable.
>
>>
>> Still, it raises the obvious question of whether "dict.kv" is much
>> better than "dictkv", which anyone can write for himself as a one-liner
>> if he wants it...
>>
>
> I think this is one of those cases where the gain is small enough that
> writing the helper function is often not worth it, but big enough that
> people would use it if it already existed. That might be a small window,
> but it's there.
>



More information about the Python-ideas mailing list