https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/removeduplicates?action=resume_content_item
I can’t figure out where’s wrong. I didn’t know about the statement “if x not in list” until recently. The results always return [].
def remove_duplicates(numbers):
new_list=[]
for x in numbers:
for i in new_list:
if x!=i:
new_list.append(x)
return new_list
print remove_duplicates([1,2,2,3])
i added a print statement to your code:
def remove_duplicates(numbers):
new_list=[]
for x in numbers:
for i in new_list:
print "i get here"
if x!=i:
new_list.append(x)
return new_list
print remove_duplicates([1,2,2,3])
but we never see it. new_list is empty, so for i in new_list
has nothing to do, so it won’t run.