Skip to content

Instantly share code, notes, and snippets.

@Estivales
Last active May 23, 2019 19:09
Show Gist options
  • Save Estivales/ec8cdc3c43768061b5ecb49b5486159a to your computer and use it in GitHub Desktop.
Save Estivales/ec8cdc3c43768061b5ecb49b5486159a to your computer and use it in GitHub Desktop.
How to find a value in a list of python dictionaries
list_of_dict = [{"name": "Douglas", "surname": "Estivales"},
{"name": "Bruce", "surname": "Silva"},
{"name": "Joaquim", "surname": "Teixeira"},
{"name": "Mohammed", "surname": "Lee"}]
search_for_name = "Douglas"
result = next((l for l in list_of_dict if l['name'] == search_for_name), None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment