Created
February 1, 2017 03:29
-
-
Save shamikalashawn/3b79edf173130147c73dcaf81a782ec4 to your computer and use it in GitHub Desktop.
Take a dictionary, with its keys and values, and I can make the values keys and turn the keys into values!
This file contains hidden or 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 invert_dict(a_dict): | |
idict = {} | |
keylist = [] | |
valuelist = [] | |
for key in a_dict: | |
keylist.append(key) | |
for value in a_dict.values(): | |
valuelist.append(value) | |
idict = dict(zip(valuelist, keylist)) | |
return idict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment