Question: Python question please help! thank you so much Question 3: (15 marks) Write a function called merge_dict that takes two dictionaries, merge them, and returns
Python question please help! thank you so much

Question 3: (15 marks) Write a function called merge_dict that takes two dictionaries, merge them, and returns a new dictionary. The returned dictionary should contain all the keys of the passed dictionaries. Moreover, the values of the common keys will be merged together in one list. However, the values of the unique keys should stay in the same format they have appeared in the input dictionaries. For example if you had the following dictionaries: d1 = {1:"Moh", 2:"Aseel", 3:"Batoul", 4:["Taylor", "Chan", "Laura"]} d2 = {1: "Nahid", 2:"Carter", 3:"John", 6:"Odak"} Output: {1: ['Nahid', 'Moh'], 2: ['Carter', 'Aseel'], 3: [' John', 'Batoul' ], 6: 'Odak' , 4: ['Taylor', 'Chan', 'Laura' ] } Another Example: d1 = {1: "Moh", 2: "Aseel", 3: "Batoul", 4: ["Taylor", "Chan", "Laura"]} d2 = {1: "Nahid", 2: "Carter", 5: "John", 4:"Odak"} output : {1: ['Nahid', 'Moh'], 2: ['Carter', 'Aseel'], 5: 'John', 4: ['Taylor', 'Chan' , 'Laura', 'Odak' ], 3: 'Batoul'}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
