I am trying to remove a dictionary from a list if it already exists but it doesn’t seem to be working. Can anyone see what I am doing wrong or advise me what I should be doing
new_dict = {'value': 'some value', 'key': 'someKey'}
if new_dict in my_list:
my_list.remove(new_dict)
new_list is a list of dictionaries where new_dict is definitely in
If
new_dictis “definitely” inmy_list, thenmy_list.remove(new_dict)should do the trick (i.e., no need for theif new_dict in my_list, that just slows it down).