Last active
August 29, 2015 14:04
-
-
Save embayer/5e9a34c972e4cf331814 to your computer and use it in GitHub Desktop.
Switch keys and values in a dict
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
# 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