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

Ian Foote ian at feete.org
Tue Feb 16 18:48:02 EST 2016


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

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.

-------------- 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/20160216/6825a265/attachment.sig>


More information about the Python-ideas mailing list