Write a Python program to concatenate following dictionaries to create a new one


The program creates three dictionaries d1, d2, and d3 with different key-value pairs. Then, an empty dictionary d4 is created. A for loop is used to iterate through the tuple (d1, d2, d3) which contains the three dictionaries. Within the loop, the update method is used to merge each dictionary into the d4 dictionary. The update method takes the key-value pairs from each dictionary in turn and adds them to the d4 dictionary.

Finally, the merged dictionary d4 is printed to show the result, which is a single dictionary containing all the key-value pairs from the three original dictionaries. In summary, the program demonstrates how to merge multiple dictionaries into a single dictionary in Python using the update method.

Source Code

d1={"Name":"Ram" , "Age":23}
d2={"City": "Salem", "Gender": "Male"}
d3={"Mark":450}
d4 = {}
for d in (d1, d2, d3): d4.update(d)
print(d4)

Output


{'Name': 'Ram', 'Age': 23, 'City': 'Salem', 'Gender': 'Male', 'Mark': 450}