There are several questions on removing duplicate items from a list, but I am looking for a fast way to remove 'directly' repeated entries from a list:
myList = [1, 2, 3, 3, 2, 4, 4, 1, 4]
should become:
myList = [1, 2, 3, 2, 4, 1, 4]
So the entries which are directly repeated should 'collapse' to a single entry.
I tried:
myList = [1, 2, 3, 3, 2, 4, 4, 1, 4]
result = []
for i in range(len(myList)-1):
if(myList[i] != myList[i+1]):
result.append(myList[i])
if(myList[-1] != myList[-2]):
result.append(myList[-1])
print(result)
Which seems to work, but it's a little ugly (how it deals with the end, and large).
I'm wondering if there is a better way to do this (shorter), and more importantly if there is a faster way to do this.