Question: Given a dictionary d, create a new dictionary that is the invert of d such that original key:value pairs i:j are now related j:i, but
Given a dictionary d, create a new dictionary that is the invert of d such that original key:value pairs i:j are now related j:i, but when there are nonunique values (j's) in d, they should not be included as a key:value pair in the inverted dictionary. Keys are case sensitive. It returns the new inverted dictionary.
>> invert({'one':1, 'two':2, 'uno':1, 'dos':2, 'three':3}) {3: 'three'} >>> invert({'one':1, 'two':2, 'three':3, 'four':4}) {1: 'one', 2: 'two', 3: 'three', 4: 'four'} >>> invert({'123-456-78':'Sara', '987-12-585':'Alex', '258715':'sara', '00000':'Alex'}) {'Sara': '123-456-78', 'sara': '258715'} # Dont forget dictionaries are unsorted collection
PYTHON
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
