Remove duplicates


#1

This is my code

def remove_duplicates(numbers):
    result=[]
    for i in range(len(numbers)):
        if i==0:
            result.append(numbers[i])
        else:
            if numbers[i]!=result:
                result.append(numbers[i])
            
    return result
remove_duplicates([1,1,2,2])

This is the error:
Oops, try again. remove_duplicates([4, 5, 5, 4]) returned [4, 5, 5, 4] instead of [4, 5]

Can some one guide me? I cannot find any error in my code


#2

here:

if numbers[i]!=result:

numbers[i] will be integers (values from the list) where result is a list. A integer will not equal a list, so this condition is always true

we can use the in keyword to check if numbers[i] is present in result


#3

Thanks a lot is worked!!


#4