14. Remove_duplicates - I can go to next lesson, but code isn't doing what it's supposed to


I was doing this exercise and looked around at the forums to get some help, and i have this code now. When I call the function like this -

print remove_duplicates([1,1,2,3,3])

it returns -

[1, 2, 3]

Then i can go to the next exercise even though it didn't just return duplicates. My code is below. What can i change to do this correctly?

def remove_duplicates(x):
    loop = []
    for i in x:
        if i not in loop:
    return loop
print remove_duplicates([1,1,2,3,3])


Or is this exercise only for lists that have duplicates?


your code is fine? the purpose of the exercise is to return a list which no longer contains duplicates. if a number occurred multiply times, only one of this instances should be in the list returned, which your code does perfectly

it is not suppose to cleanse the list completely from numbers which occur multiply times


Oh! i thought it was only supposed to return the numbers that had duplicates. That makes so much more sense. Thanks :joy:


well, nothing is stopping you from writing such a program, but it was not the purpose of this exercise/program


Exactly. Thank you for replying! :relaxed:


no problem, glad that i could clarify :slight_smile:


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