Skip to content

Instantly share code, notes, and snippets.

@shamikalashawn
Created February 1, 2017 03:29
Show Gist options
  • Save shamikalashawn/3b79edf173130147c73dcaf81a782ec4 to your computer and use it in GitHub Desktop.
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!
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