14. remove_duplicates



My code is either skipping the first if statement or the second for loop. Either way, it won't append anything into edit so the program continues to return [].

"Oops, try again. remove_duplicates([4, 5, 5, 4]) returned [] instead of [4, 5]"

def remove_duplicates(lst):
    edit = []
    for n in lst:
        if lst.count(n) > 1:
            for i in edit:
                if n != i:
    return edit



Since we are creating a new list, how about using it as a lookup? We would iterate over the argument list, and if the item is not found in the lookup list, append it, otherwise continue.


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