Created
July 24, 2012 18:28
-
-
Save rcaldwel/3171677 to your computer and use it in GitHub Desktop.
python: find a key 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
def find_key(dic, val): | |
"""return the key of dictionary dic given the value""" | |
return [k for k, v in dic.iteritems() if v == val][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment