I have an issue with removing consecutive duplicates in a list without removing all duplicates.
Say I have a list,
a = [3,3,3,4,10,11,3,3,5,5,10]
What I want to do is whenever there is a duplicate in a row, that duplicate is changed to a single value. I want this to happen for any number of consecutive duplicates. Thus I want my new a to be,
new_a = [3,4,10,11,3,5,10]
Notice I don't want to remove the other duplicates, like the set function would do, I just want to change consecutive duplicates into one value.
Here is my attempt, which works sometimes but not on all my lists, most likely because I'm not sure how to set up the general rule for my range.
for i in range(0, len(set(a))-1):
if a[i] == a[i+1]:
a.pop(i+1)
Any help would be great, thanks.