I have list
with the following values:
numeros = [5, 3, 1, 2, 3, 4, 5, 5, 5]
In Python would have some function to count how many times some value repeats?
For example: I want to know how many times 5
has repeated.
I have list
with the following values:
numeros = [5, 3, 1, 2, 3, 4, 5, 5, 5]
In Python would have some function to count how many times some value repeats?
For example: I want to know how many times 5
has repeated.
Only use the method count()
numeros = [5, 3, 1, 2, 3, 4, 5, 5, 5]
numeros.count(5)
You can use Counter
:
import collections
numeros = [5, 3, 1, 2, 3, 4, 5, 5, 5]
repetidos = collections.Counter(numeros)
print(repetidos[5])
See running on ideone .
If you prefer the short form:
print(collections.Counter([5, 3, 1, 2, 3, 4, 5, 5, 5])[5])