Suppose, I have a list below
list = [1,1,1,1,2,3,1,4,4,4,4,3,3]
I want to remove the duplicates which occur more than twice. Basically, I want like this
[1,1,2,3,4,4,3,3]
I use the following code
i = 0
while i < len(list) -2:
if list[i] == list[i+2]:
del list[i+2]
else:
i = i+2
this code gives me the following output
[1, 1, 2, 3, 1, 4, 4, 4, 3, 3]
Here 4 occurs thrice, but I want twice. How can I modify the code or any other method that could give the desired output?