Answers for "python count number of times value appears in list"

1

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})
Posted by: Guest on April-05-2021
1

count how many times a value appears in array python

>>> [1, 2, 3, 4, 1, 4, 1].count(1)
3
Posted by: Guest on September-02-2020

Code answers related to "python count number of times value appears in list"

Python Answers by Framework

Browse Popular Code Answers by Language