Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Sample output ('a' 100,:300, ' 200, 'd':400) Exercise 4 Write a function called merge2 that takes two dictionaries as parameters. These in these input lists,
Sample output ('a' 100,:300, ' 200, 'd':400) Exercise 4 Write a function called merge2 that takes two dictionaries as parameters. These in these input lists, the values will always be integers. This function will create a new dictionary that contains everything from the two input dictionaries and return it. If the input lists have common keys, the merged dictionary will have the sum of the values for each common key. Create a few dictionaries, print them to screen using the function created above. After this, merge them using the function you wrote and print the result to screen Sample input d1 -('a':100, 'b': 200, c':300 d2-'a': 300, 'b': 200, 'd :400) Sample output ('a:400, 'b: 400, 'd:400, :300) Exercise5 Write a function called merge3 that takes two dictionaries as parameters. This function will create a new dictionary that contains everything from the two input dictionaries and return it. The only difference is that the values will now be stored in a list, not just as a single value. If the input lists have common keys, the merged dictionary will have a list of the values form in the input dictionaries for the common key. Create a few dictionaries, print them to screen using the function created above. After this, merge them using the function you wrote and print the result to screen. Sample input d1-'a' 100, 200, :300) d2-'a': 300, 'b': 200, 'd :400) Sample output ('a' [100,3001'[200,200],c': 1300], 'd': [400]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started