Dec-14-2019, 07:16 PM
I have a list of tuples, and I am trying to delete some tuples of the list based on their first element: if the first element is the same first element of the next tuple, then the second tuple, which contains that same first element, should be deleted. I tried doing it through an iterative loop, but it doesn't completely work. Some duplicates are still left in the list.
for tuple in list: index_of_the_first_tuple=list.index(tuple) if tuple[0] in list[index_of_the_first_tuple+1]: list.pop(index_of_the_first_tuple+1)