How can I count the occurrences of a list item?
Given an item, how can I count its occurrences in a list in Python?
Joshua C.
answered 04/07/19
Software Engineer
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.