The update Method in Python: Updating a Dictionary

Update a dictionary by adding elements from another dictionary. If keys overlap, values are overwritten.

update([other])

  • other: Dictionary whose elements are added to the current dictionary.
a = {'one': 1, 'two': 2}
b = {'two': 22, 'three': 3}
a.update(b)
print(a)  # {'one': 1, 'two': 22, 'three': 3}