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

Ian Foote ian at feete.org
Tue Feb 16 20:15:51 EST 2016


On 17/02/16 00:34, MRAB wrote:
> 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)"?
> 

Given a dictionary d, I would expect your dict.from_items to satisfy:

    dict.from_items(d.items()) == d

But this is how dict already behaves:

    dict(d.items()) == d.

What a new classmethod would satisfy is:

    dict.zip(d.keys(), d.values()) == d

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160217/84ac83ff/attachment.sig>


More information about the Python-ideas mailing list