3 ms·
Or dictAB = dict(dictA, **dictB) in Python 2 and 3.
by vanni 9y ago
Or
dictAB = dict(dictA, **dictB)
in Python 2 and 3.
- dom0 9y agoThat'll create an intermediate dict (due to the unpacking) for Python <3.6 and then another dict. a.update(b) does neither. It also has different semantics from a.update(b). The unpacking way will explode when both a and b contain the same key, while a.update(b) does not; existing keys also contained in b will be overwritten by the values from b.