How do I check if there is a repeated string in a list?

0

I would like to learn an easier way to check all items in a list and look for repeated strings.

I'm currently doing this:

elif "azul" in fios[0] and fios[1] or "azul" in fios[1] and fios[2] or "azul" in fios[0] and fios[2]:
    print("Corte o último fio azul")

My intention is to check if there is more than one "blue" within the wires list, the code is working, but I would like to make it more practical.

    
asked by anonymous 02.04.2018 / 21:54

1 answer

0

Just use the count method of object list :

cores = ['azul', 'amarelo', 'vermelho', 'preto']

print(cores.count('azul'))  # 1

cores = ['azul', 'amarelo', 'vermelho', 'azul']

print(cores.count('azul'))  # 2
    
02.04.2018 / 22:03