Remove Duplicates 15.14


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/4?curriculum_id=4f89dab3d788890003000096#


For the life of me I cannot work out why I recieve an error stating "remove_duplicates([4,5,5,4]) returned [] instead of [4,5]


def remove_duplicate(numbers):
    new_list =[]
    for i in numbers:
        if i not in new_list:
            new_list.append(i)
    return new_list


#2

This can only be an indentation problem because I have tested your code and it runs fine all you need to do is indent it properly,

def remove_duplicates(numbers):
    new_list = []
    for i in numbers:
        if i not in new_list:
            new_list.append(i)
    return new_list

and call your function with a list as the parameter for example,

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

should return,

> [1,2,3,4]


#3

the only problem i can find is that your function is called remove_duplicate, it should be remove_duplicates


#4

Lol i didn't even notice that myself :laughing: Keen eye! :smile:


#5

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