1. update()
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict1.update(dict2)
print(dict1)
2. dict(dict1, **dict2)
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict3 = dict(dict1,**dict2)
print(dict3)
3. dict(dict1.items() | dict2.items())
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict3 = dict(dict1.items() | dict2.items())
print(dict3)
4. itertools
import itertools
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict3 = dict(itertools.chain(dict1.items(), dict2.items()))
print(dict3)
5. ChainMap
from collections import ChainMap
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict3 = dict(ChainMap(dict1, dict2))
print(dict3)
|