How do I know if a list has several equal values?

Asked

Viewed 28 times

-1

I am wanting to make a function that returns the equal elements of a list.

cartas_jogador_a = ['4', '7', '10', '8', '1', '10']

I wanted to get only the values '10', '10' in another list, already tried using the while and for loop but did not get result.

  • 2

    https://answall.com/questions/216413/identificar-elements-repeaters-lista-com-python can help you :)

1 answer

-2

You can use a for to compare all list elements with the value you are looking for.

cartas_jogador = [1,2,8,4,5,6,7,8]
for carta in cartas_jogador:
    valor_objetivo = 8
    if carta == valor_objetivo:
       outra_lista.append(carta)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.