I've got a Python list of dictionaries, as follows:
a = [
{'main_color': 'red', 'second_color':'blue'},
{'main_color': 'yellow', 'second_color':'green'},
{'main_color': 'yellow', 'second_color':'blue'},
]
I'd like to check whether a dictionary with a particular key/value already exists in the list, as follows:
// is a dict with 'main_color'='red' in the list already?
// if not: add item
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…