How can I count the occurrences of a list item?
Given an item, how can I count its occurrences in a list in Python?
Inactive Tutor
answered 04/07/19
from collections import Counter
bag = ['a', 'b', 'c', 'c']
c = Counter(bag)
print(c['a'])
Still looking for help? Get the right answer, fast.
OR
Find an Online Tutor Now
Choose an expert and meet online.
No packages or subscriptions, pay only for the time you need.