Remove duplicates


#1

Hi,

I'm struggling with the Purify exercise. I'm not sure if this is even a decent way of doing this, but this is what I have so far:

 def remove_duplicates(x):
    new_list = []
    for items in x:
        while x.count(items) >1:
            new_list.append(items)
    return new_list

It gives me the following error: Oops, try again. remove_duplicates([4,5,5,4]) resulted in an error:

And that's it. It's not specifying the error. Any help would be appreciated!

Link to exercise


#2

This line is creating an infinite loop.


#3

Ah yes, of course. Brain fart I guess. Thanks for the heads up!


#4

What if you loop over the original list, and if not found in the temporary list, append it?


#5

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