Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
A Cleaner Way to Merge Dictionaries in Python
May 21, 2026
If you're still using `.update()` or the double-asterisk unpacking trick `**dict_a, **dict_b` to merge dictionaries in Python, there's a much cleaner way now. Since Python 3.9, you can use the union operator (`|`) to merge two dictionaries in a single, highly readable line.
For example, `merged_dict = dict_a | dict_b` returns a brand new dictionary combining both, with values from `dict_b` overwriting duplicates. If you want to update the original dictionary in place, you can use the update operator `|=`. It's a small syntactic sugar that makes your codebase look modern and much easier to read at a glance.