Tom Ritchford
Mar 14, 2023

--

No, it's a shorter way. Constructing a dictionary that way turns out to be significantly slower (try it!)

Why? Because Python has to do two extra things.

First it has to look up the symbol dict, first in locals(), then in globals() and finally in __builtins__.

Then it constructs a dictionary of all the arguments - but then it passes that dictionary to the dict constructor, where it gets copied into a new dictionary!

It is almost certain that this would never make any practical difference, but I still avoid doing it unless I have to. And recent versions of Python have things like {**d1, **d2} or d1 | d2 so I never have use it.

--

--

Responses (1)