remove_duplicates


#1

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

def remove_duplicates(lst):
    llist = []
    for item in lst:
        llist.append(lst)
        if item not in llist:
            return item
    return llist
print remove_duplicates([1, 1, 2, 2])

1
None
This is console output. I can get to next exercise, but my output is not good...


#2

Shouldn't you append item to the llist if item is not in list:

for item in lst:
    if item not in llist:
        /* append item to llist */

careful, the moment return is reached, the function ends!


#3

Yeah I made stupid mistake :smiley:

def remove_duplicates(lst):
    llist = []
    for item in lst:
        if item not in llist:
            llist.append(item)
    return llist
print remove_duplicates([1, 1, 2, 2])

tnx

This is output now:
[1, 2]
None