I followed another post on here to create a function that receives a list of numbers and removes all adjacent duplicate numbers. It is working for all my test cases except the one below. The logic makes sense to me and I'm just not seeing where I'm going wrong. If anyone can help I'd greatly appreciate it.
def removeAdjacentNumbers(numList):
previous = ''
for i in numList[:]:
if i == previous:
numList.remove(i)
else:
previous = i
return numList
def main():
print(removeAdjacentNumbers([2,2,4,4,2,2,5,5]))
if __name__== "__main__":
main()
It is returning:
[4, 2, 2, 5]
And is supposed to return:
[2, 4, 2, 5]