I have a list of dictionaries like this :
[{'Name': 'Andri', 'Age': '20'}, {'Name': 'Nova', 'Age':'24'}]
Now my question is how can I verify if Nova
is a member of the dictionaries or not?
I have a list of dictionaries like this :
[{'Name': 'Andri', 'Age': '20'}, {'Name': 'Nova', 'Age':'24'}]
Now my question is how can I verify if Nova
is a member of the dictionaries or not?
how i can verified if Nova is a member of the dictionaries or no
This to me sounds like you just want a True
or False
if 'Nova'
exists.
You can use any()
to check if 'Nova'
exists in the 'Name'
key:
>>> d = [{'Name': 'Andri', 'Age': 20}, {'Name': 'Nova', 'Age': 24}]
>>> any(x['Name'] == 'Nova' for x in d)
True
Or you can check the values()
specifically:
>>> any(v == 'Nova' for x in d for v in x.values())
True
Or using the in
operator:
>>> any('Nova' in x.values() for x in d)
True
if 'Nova' in #dictionaryName.itervalues():