how to Check if value already exists or not within list of dictionaries?
Example;
a = [{ 'main_color': 'red', 'second_color':'blue'},
{ 'main_color': 'yellow', 'second_color':'green'},
{ 'main_color': 'yellow', 'second_color':'blue'}]
if any(d.get('main_color') == 'red' for d in a):
//if value is exit returns true
else:
//false
Comments
Post a Comment