Skip to content

Instantly share code, notes, and snippets.

@zhannes
Created December 19, 2013 22:48
Show Gist options
  • Save zhannes/8047580 to your computer and use it in GitHub Desktop.
Save zhannes/8047580 to your computer and use it in GitHub Desktop.
>>> d = {'a': 'foo', 'b': 'bar'}
>>> d
{'a': 'foo', 'b': 'bar'}
# get name of matching prop
>>> matches = [item for item in d if d[item] =='bar']
>>> matches
['b']
# or, get the value of the match
>>> matches = [d[item] for item in d if d[item] =='bar']
>>> matches
['bar']
# or, pair
matches = [(item,d[item]) for item in d if d[item] =='bar']
>>> matches
[('b', 'bar')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment