Practice Markes Perfect_remove_duplicates


#1

Hi Master,
My code can pass the test, but i don't think it's good, is it right ?

Code is here:

def remove_duplicates(x):
    l = []
    y = x
    
    for i in x:
        z = i
    return z
    for e in y:
        if e == z:
            l = y.remove(e)
    return l
    
    
    
z = [1,2,2]
print remove_duplicates(z)

#2

There is something wrong about this program.
This should have halted after first loop as return is there.
if you test this code on .. [1,1,2,2] it returns 2 but it has to return [1,2].
This o/p w.r.t to code is right but w.r.t exercise it should not be passed.
(Point me out if I'm wrong about this)


#3

yes ,you are right, i will be to change my code.


#4

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