Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

count how many times a value shows in python list

#use count():
>>> my_list = [1, 2, 3, 1, 4]
>>> print(my_list.count(1))
2

#OR, you can also use counter:
>>> from collections import Counter
>>> z = ['blue', 'red', 'blue', 'yellow', 'blue', 'red']
>>> Counter(z)
Counter({'blue': 3, 'red': 2, 'yellow': 1})
 
PREVIOUS NEXT
Tagged: #count #times #shows #python #list
ADD COMMENT
Topic
Name
5+1 =