Created
December 19, 2013 22:48
-
-
Save zhannes/8047580 to your computer and use it in GitHub Desktop.
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
>>> 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