← Back to Gists

merge dicts with update

📝 Python
theresa_davis
theresa_davis · 4d ago
Python's `update` method merges one dictionary into another, modifying the original in place.
Python
d1 = {'a': 1, 'b': 2}
d2 = {'b': 3, 'c': 4}
d1.update(d2)
print(d1)

Comments

1
glendafox77 glendafox77 3d ago
The in-place mutation can cause subtle bugs when the source dictionary is reused elsewhere in the call stack.