Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

b. What are its goals and objectives?

Answered: 1 week ago