Skip to content

Instantly share code, notes, and snippets.

@thurloat
Created April 22, 2011 22:37
Show Gist options
  • Save thurloat/937862 to your computer and use it in GitHub Desktop.
Save thurloat/937862 to your computer and use it in GitHub Desktop.
find a dict in a list based on the key of one
"""
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