I want to delete all dictionaries that have 'original_y' key. But no matter what I do, I can only delete the first item. Below is the code
list1 = [{'original_x': 70, 'original_y': 134, 'original_count': 1},{'original_x': 78, 'original_y': 134, 'original_count': 2}, \
{'matched_x': 73, 'matched_y': 130, 'matched_pixel_count': 3}, {'matched_x': 73, 'matched_y': 130, 'matched_pixel_count': 3}, {'matched_x': 71, 'matched_y': 132, 'matched_pixel_count': 1}, \
{'matched_x': 76, 'matched_y': 132, 'matched_pixel_count': 2}, {'matched_x': 71, 'matched_y': 132, 'matched_pixel_count': 1}, {'matched_x': 76, 'matched_y': 132, 'matched_pixel_count': 2}, \
{'matched_x': 71, 'matched_y': 133, 'matched_pixel_count': 1}, {'matched_x': 78, 'matched_y': 133, 'matched_pixel_count': 1}, {'matched_x': 71, 'matched_y': 133, 'matched_pixel_count': 1}]
list1_copy = list1.copy()
index = 0
delete_list = []
for each_dict in list1:
if 'original_y' in each_dict:
print(" index is " + str(index) + " " + str(list1[index]) )
delete_list.append(index)
index += 1
print(list1[1])
list1.pop(0)
list1.pop(1)
print(list1)
Help would be appreciated.