Question: a 9. Write a function swap(d, key1, key2) that takes a dictionary and two keys and swaps the values corresponding to both keys. If any

 a 9. Write a function swap(d, key1, key2) that takes a

a 9. Write a function swap(d, key1, key2) that takes a dictionary and two keys and swaps the values corresponding to both keys. If any of the keys is not present in the dictionary, the function should print an error message. Sample Function Calls Sample Return values swap({1:'a', 2: 'b'], 1, 2) swap({1:'a', 2: 'b'}, 1, 3) {1:'b', 2: 'a'} "3 is not a key in the dictionary

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!