Lesson 14 remove_duplicates


rodo o codigo ,vem aviso de erro dizendo que retorna [4,5,4] e no consoçeretornao reultado correto [4,5]
onde esta o erro!

def remove_duplicates(c):

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

[4, 5]

Replace this line with your code. 
def remove_duplicates(c):
    for i in c:
        if i not in b:
    return b
print remove_duplicates([4,5,5,4])


this line:


should be inside the function, given the exercise (to test if your code is correctly) only calls the function, and not the whole script. Also, remove this line:


because the exercise also checks for an empty list (which will cause problems), and your for loop can handle it


este e o meu codigo,ele roda ok e volta o desejadp que e:


def remove_duplicates(a):
for i in a:
if i not in b:
return b

print remove_duplicates(a)


yes, but the exercise calls your function multiply times (only the function) so it should work for that, which is why you need to make the changes i suggested


very good , thank!!!!!!!


Did you resolve the issue?


Hello guys,

I have successfully completed this exercise but feel like I shouldn't have.. Here is my code, what do you think ?

numbers = [1, 1, 2, 2, 3, 3]
duplicates = []
def remove_duplicates(numbers):
    for n in numbers[0:len(numbers)]:
        if n > 0: 
    return n
print duplicates


seems you shouldn't have passed, but it is impossible to eliminate all corner cases


So I did it in what looks like a much more basic way than everyone else.

def remove_duplicates(x):
    new_list = []
    for i in x:
        if i not in new_list:
    return new_list    
    x = new_list    
    return x

Essentially I created a new list, and for each item that wasn't in said list I appended it.

I then set the parameter to equal this list and returned it. It worked on the first try.


You code was great!
Effective but not really efficient, last 2 lines were redundant.


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