I want to remove duplicate elements from a list and return the list that has only unique values. Here is my code
def remove_dup(nums):
for i in range(1, len(nums)):
if nums[i] == nums[i-1]:
nums.remove(nums[i])
return nums
I am testing the code with this :
print(remove_dup([0,0,1,1,1,2,2,3,3,3,4]))
I was expecting the output to be [1,2,3,4] but I am getting [0, 1, 1, 2, 3, 3, 4]. Can anyone please explain, why?