Remove_duplicates


#1


Below this line, add a link to the EXACT exercise that you are stuck at.

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

In what way does your code behave incorrectly? Include ALL error messages.

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

What do you expect to happen instead?
It should loop through again?


def remove_duplicates(lst):
    new_lst = []
    for i in lst:
        if i in lst not in new_lst:
            new_lst.append(i)
        print new_lst
        return new_lst
        
        
remove_duplicates([4, 5, 5, 4])


#2

You already stated i in lst in your for loop. You don't need in lst anymore.

These two should be outside the loop. Function stops at return. If your return is inside the loop, it will only loop once and stops so it will never loop more than once.


#3

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