Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RicardoTurco/ea60b1231fad3f62eb1cc2620ea22693 to your computer and use it in GitHub Desktop.
Save RicardoTurco/ea60b1231fad3f62eb1cc2620ea22693 to your computer and use it in GitHub Desktop.
Python: encontrando valor dentro de uma lista de dicionários
def in_dictlist(key, value, my_dictlist):
'''
Verify if an value is contained in a dictionary list.
:param key: KEY where the VALUE will be searchead
:param value: VALUE to be found
:param my_dictlist: Dictionary where the search will be make it
:return: TRUE if "value" (param) exists in "my_dictlist" (param)
'''
for this in my_dictlist:
if this[key] == value:
return True
return False
list_dict = [
{"source": "item1"},
{"source": "item2"},
{"source": "item3"},
]
if in_dictlist("source", "item3", list_dict):
print('Found')
else:
print('NOT found')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment