Check if value already exists within list of dictionaries?
Here’s one way to do it: if not any(d[‘main_color’] == ‘red’ for d in a): # does not exist The part in parentheses is a generator expression that returns True for each dictionary that has the key-value pair you are looking for, otherwise False. If the key could also be missing the above code can … Read more