I don't know why this isnt working



Oops, try again. remove_duplicates([4, 5, 5, 4]) returned [4, 5, 4] instead of [4, 5]

def remove_duplicates(lst):
    one = []
    for index, i in enumerate(lst):
        if index == len(lst)-1:
        elif(lst[index] != lst[index + 1]):
    return one


not sure about the logic of this line:

elif(lst[index] != lst[index + 1]):

the list needs to remove all duplicate values, not successive duplicate values which i think this code does


Well that line is supposed to check the current element and the element one
place ahead of it. If they are not the same that means that they are not
duplicates and it will go into the new list that will only contain originals


but if we have the following list:


the result should be [1,2,3], your code wouldn't remove the 1 at the end, given they are not next to each other, even though it should


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.