Created
April 22, 2011 22:37
-
-
Save thurloat/937862 to your computer and use it in GitHub Desktop.
find a dict in a list based on the key of one
This file contains 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
""" | |
Find a dict (plan) in a list based on the 'key' key. | |
""" | |
ORG_PLANS = [ | |
{ | |
'key': "schoolzone", | |
'name': 'School Zone', | |
'seats': 3, | |
'price': 9 | |
}, | |
{ | |
'key': 'highway', | |
'name': 'Highway', | |
'seats': 10, | |
'price': 19 | |
}, | |
] | |
# I want plan "highway" | |
plan = 'highway' | |
dict_i_want = [x for x in settings.ORG_PLANS if x['key'] == plan] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment