Skip to content

Instantly share code, notes, and snippets.

@rcaldwel
Created July 24, 2012 18:28
Show Gist options
  • Save rcaldwel/3171677 to your computer and use it in GitHub Desktop.
Save rcaldwel/3171677 to your computer and use it in GitHub Desktop.
python: find a key in a dict
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