How do you merge two dictionaries?

Python lists, dictionaries and sets · Freshers and experienced

Model answer

In Python 3.9 and later use d1 | d2 (right side wins on duplicate keys), or d1.update(d2) to change d1 in place. Older style is {**d1, **d2}.

Learn this topic

Dictionaries, Tuples and Sets in Python in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions