Remove_duplicates


#1

def remove_duplicates(numbers):
    c=numbers
    
    new=[]
    n=0
    for x in numbers:
        count=0
        for k in c:
            n=n+1
            print n
            if k==x:
                count=count+1
                print count
        if count==1:
                    new.append(x)
                    
    return new

what's wrong with my code


#2

if i would have the list [4,5,5,4] the count for both would be 2, we can see this:

def remove_duplicates(numbers):
    c=numbers
    
    new=[]
    n=0
    for x in numbers:
        count=0
        for k in c:
            n=n+1
            if k==x:
                count=count+1
        print count
        if count==1:
                new.append(x)
                    
    return new
print remove_duplicates([4,5,5,4])

in other words, nothing would get pushed into the hits array.

Maybe check the hint in the lessoN?


#5

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