14.remove_duplicates help


Hello, I cant figure out how this actually would work for every situation, instead of when the list got only exactly two kinds of the same number. Can someone continue my thought of doing this function

Oops, try again. remove_duplicates([6, 8, 122, 2, 18]) returned [8, 8, 8, 8, 122, 122] instead of [8, 122, 18, 2, 6]

I can understand that my code is working for only if a number appears twice

def remove_duplicates(list):
    newlist = []
    counter = 2
    for i in list:
        for j in list:
            if i == j :
                counter = counter - 1
            if counter == 0:
    return newlist


I am very sorry, but the method you are using is rather inefficient. I sort of try to understand what you are trying to do, but it is not going to work.

If i where you, i would loop over the list:

for i in list:

then, check if the item is not in the new list:

if i not in newlist:

if this if statement is true, append the item to the list


I dont know why I made it hard for myself but your solution was straight forward to it, thank you stetim for your help!