CBSE Class 12 Computer Science Question 94 of 120

Review of Python Basics — Question 46

Back to all questions
46
Question

Question 41

Write a Python script to merge two Python dictionaries.

Solution
dict1 = eval(input("Enter the first dictionary: "))
dict2 = eval(input("Enter the second dictionary: "))
dict1.update(dict2)
print("Merged dictionary:", dict1)
Output
Enter the first dictionary: {1 : "Orange", 2: "Mango", 3 : "Watermelon"}
Enter the second dictionary: {4 : "Pineapple", 5 : "Banana"}
Merged dictionary: {1: 'Orange', 2: 'Mango', 3: 'Watermelon', 4: 'Pineapple', 5: 'Banana'}
Answer