Union of dict objects in Python
You can also use update
method of dict like
a = {'a' : 0, 'b' : 1}
b = {'c' : 2}
a.update(b)
print a
This question provides an idiom. You use one of the dicts as keyword arguments to the dict()
constructor:
dict(y, **x)
Duplicates are resolved in favor of the value in x
; for example
dict({'a' : 'y[a]'}, **{'a', 'x[a]'}) == {'a' : 'x[a]'}