Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

# invert a dictionary

# 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'}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #invert #dictionary
ADD COMMENT
Topic
Name
2+6 =