14. remove_duplicates Cant make code work


#1



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


It doesnt return any value


To return the values............So i just noticed now that the problem was the last for ,wouldnt append because there was no key with 1 value , all had at least 2 my bad, the post can be locked


def remove_duplicates(lista):
    contagens = { } #dict with number and the number of apparitions
    listafinal = [] #final list to return
    
    
    for itens in lista:
        for elementos in contagens: 
            if itens == elementos:
                contagens[elementos] += 1
                break           
        else:
            contagens.update({itens:1})
        
    for i in contagens:
        if contagens[i] == 1:
            listafinal.append(i)
            
    return listafinal


#2

creating the contagens goes pretty well, but lets say i have this list:

[4,5,5,4]

you will get:

{4: 2,5: 2}

then i don't understand this:

    for i in contagens:
        if contagens[i] == 1:
            listafinal.append(i)

why an if condition? each key in your dictionary will be unique, you can just append it to the list. You can just remove the if condition


#3

I didnt realize that the if was useless until too late .


#5

But did you resolve it?


#6

Yes i did, thanks , i must had brainlag when i tried that if