dict1.update( dict2 )
This is asymmetric because you need to choose what to do with duplicate keys; in this case, dict2 overwrite dict1 . Exchange them differently.
EDIT: Ah, sorry, didn't see this.
This can be done in one expression:
>>> from itertools import chain >>> dict( chain( *map( dict.items, theDicts ) ) ) {'a': 1, 'c': 1, 'b': 2, 'd': 2}
There is no credit for this last!
However, I would say that it could be more Pythonic (explicit> implicit, flat> nested) to do this with a simple for loop. YMMV.
katrielalex Aug 16 2018-10-16T00: 00Z
source share