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

Popular posts from this blog

How to get Full URL or get absolute url In Django

How To Convert Html File/URL/String Into Image Using Python

How to Connect Firebase Using Pyrebase In Python