Python Program to Concatenate Two Dictionaries Into One

Python Program to Concatenate Two Dictionaries Into One

In this tutorial, we will learn about how to concatenate two dictionaries into one dictionary.

Explanation ✏

  1. First, we need to create two dictionaries

  2. Then, with the help of the update() function we can add a second to the first dictionary.

  3. Finally, print the output

Code 👩‍💻

dict1 = {'a':5,'b':10,'c':15}
dict2 = {'d':20,'e':25,'f':30}
dict1.update(dict2)
print(dict1)

Output : {'a':5, 'b':10, 'c':15, 'd':20, 'e':25, 'f':30}

Another Method:- Another way to merge two Python dictionaries using (**)

Code 👩‍💻

dict1 = {'a':5,'b':10,'c':15}
dict2 = {'d':20,'e':25,'f':30}
print({**dict1, **dict2})