# invert a dictionary def inv_dict(obj): return { value: key for key, value in obj.items() } d = {'apple':1, 'oranges':2, 'bananas':3} print(d) print(inv_dict(d)) # Output: # {1: 'apple', 2: 'oranges', 3: 'bananas'}