Question: Write a Python function called addDicts (d1, d2), which takes two dictionaries, d1 and d2, as parameters, and combines them. You may assume that d1

Write a Python function called addDicts (d1, d2), which takes two dictionaries, d1 and d2, as parameters, and combines them. You may assume that d1 and d2 have string keys and positive integer values. Without modifying dl or d2, your addDicts function should return a new dictionary, dSum, with the following properties Ifa key was in both d1 and d2, the key will be in dSum, and the value associated with the key in dSum should be the sum of the values for that key in dl and d:2 If a key was in either d1 or d2 but not both, the key will be in dSum, and the value associated with the key should be whatever the value for the key was in d1 or d2 Ifa key was in neither d1 nor d2, the key should not appear in dSum. Constraints . Do not import/use any Python modules. You may use any dictionary method that is appropriate to solving this problem . Your submission should have no code outside of the addDicts function (comments are fine) Your addDicts function must not modify the dictionaries that are passed in as arguments. Examples (note that items in dictionaries may appear in an order different from the order below): >>> alFruits apples':1, 'bananas': 12, "pears'7 >>> bethFruits'pears':, 'apples':3, 'cherries':6 >>> codyFruits >>> addDicts (alFruits,bethFruits) 'apples' 4, 'pears' 15, 'cherries': 6, 'bananas 12 >>> addDicts (alFruits,codyFruits) 'apples': 1, 'pears' 7, 'bananas' 12) >>>alFruits 'apples'1, 'pears': 7, 'bananas 12) >bethFruits 'apples3, 'pears 8, cherries 6) >>> codyFruits
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
