Skip to content

Instantly share code, notes, and snippets.

@embayer
Last active August 29, 2015 14:04
Show Gist options
  • Save embayer/5e9a34c972e4cf331814 to your computer and use it in GitHub Desktop.
Save embayer/5e9a34c972e4cf331814 to your computer and use it in GitHub Desktop.
Switch keys and values in a dict
# sitch keys and values in a dict
aDict = {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
inverse = dict(zip(aDict.values(), aDict.keys()))
# print the result line by line
for k, v in inverse.iteritems():
print '%s: %s' % (k, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment