Created
August 4, 2020 06:51
-
-
Save RicardoTurco/ea60b1231fad3f62eb1cc2620ea22693 to your computer and use it in GitHub Desktop.
Python: encontrando valor dentro de uma lista de dicionários
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
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