HW2.8. How am I gonna be an optimist about this?
By accident, one of your colleagues set the values for a dictionary entry to be its keys. Thankfully, the values were unique and, thus, did not violate the no duplicate rule. Help your colleague out by creating a function that they can use to swap or change a dictionary's keys with its values. That is, for each key-value pair, change the entry to be a value-key pair. Improve the resiliency of the swapping routine by allowing for duplicate values to have their old keys combined together as a list.
For example, if we want to change the following dictionary's key-value pairings:
{'keye': 2, 'key1': 4, 'key2': 1, 'key3': 2}
We would receive the output of:
{'1': ['key2'], '2': ['keye', 'key3'], '4': ['key1']}
Note: Please leave the values of the dictionary as-is. That is, please do not coerce the values of the dictionary to strings!
Your code snippet should define the following:
Name: swap_dictionary_key_value_pairs
Type: Python Function
Description: Function that swaps the key-value pair of the dictionary
user_code.py