[Python-Dev] performance of {} versus dict()
Ethan Furman
ethan at stoneleaf.us
Wed Nov 14 22:27:15 CET 2012
MRAB wrote:
> On 2012年11月14日 20:53, Mark Adam wrote:
>> On Wed, Nov 14, 2012 at 1:37 PM, Xavier Morel <catch-all at masklinn.net>
>> wrote:
>>> On 2012年11月14日, at 19:54 , Mark Adam wrote:
>>>>>>>> Merging of two dicts is done with dict.update.
>>>>>> No, dict.update merges one dict (or two) into a third one.
>>>> No. I think you need to read the docs.
>>>>>> How do you do it on
>>>> initialization? This doesn't make sense.
>>>>>> dict(d1, **d2)
>>>> That's not valid syntax is it?
>>> No.
>> You can have dict(d1) and dict(**d2), but not dict(d1, **d2).
To (mis-)quote Antoine:
>--> d1 = {1:2}
>--> d2 = {'3':4}
>--> dict(d1, **d2)
> {1: 2, '3': 4}
Apparently it is valid syntax. Just make sure you keys for the ** operator are valid strings. :)
~Ethan~
More information about the Python-Dev
mailing list