Can someone please help me take a look what is wrong in my code. The message below keep popping up when I submit the code.

"Oops, try again. Your remove_duplicates modifies the list that was passed to it. [4, 5, 5, 4] was modified to [4, 4, 5, 5]. Perhaps you should make a copy first!"

However, when I input [4, 5, 5, 4] into the function, I am getting the right answer returning [4, 5]. Thanks in advance!

def remove_duplicates(lst):
    new_list = []
    for i in range(len(lst)):
        if i == 0:
        elif lst[i] != lst[(i-1)]:
    return new_list


for this exercise, you can't modify the list which you do here:


by sorting the list, you modify it


oh haha thxxx. I missed that instruction.


what's wrong in the following code ?

def remove_duplicates(n=[]):
for i in range(len(n)):
if n[i] not in newlist:
newlist = newlist.append(n[i])
return newlist

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


newlist is a integer, it should be a list


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