Created
September 2, 2015 10:19
-
-
Save kaushik94/d8378372b06cf18bff5a to your computer and use it in GitHub Desktop.
reversing a dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverseDict(somedict): | |
newdict = {} | |
for each in somedict: | |
for one in somedict[each]: | |
newdict[one] = each | |
return newdict | |
something = {'Bob':['Harry','Jenkins', 'Onion', 'Fred', 'Earl', 'Sam'], | |
'Wayne':['Wallace', 'David', 'Eel', 'Perkins', 'Fruit', 'Angela'], | |
'Jeff':['Aaron', 'Cameron', 'Keith', 'Winston', 'Geoff', 'Wayne'] | |
} | |
newone = reverseDict(something) | |
print newone['Harry'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment