[issue36431] Use dict unpacking for merging two dicts
Terry J. Reedy
report at bugs.python.org
Tue Mar 26 20:16:13 EDT 2019
Terry J. Reedy <tjreedy at udel.edu> added the comment:
3 years ago, Trey Hunter found 11 ways to merge to a new dict.
https://treyhunner.com/2016/02/how-to-merge-dictionaries-in-python/
He followed up with a performance comparison.
https://gist.github.com/treyhunner/f35292e676efa0be1728
** unpacking was nearly twice as fast as the 2nd place methods.
(Bigger dict might change the ratio, but I expect ** unpacking to remain first.)
Trey's summary: "This is simple and Pythonic. There are quite a few symbols, but it’s fairly clear that the output is a dictionary at least." I consider the last point a major plus.
User comment: "Beautiful. Pythonic. Thank you." No negatives.
----------
nosy: +terry.reedy
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36431>
_______________________________________
More information about the Python-bugs-list
mailing list