Python ProgrammingPython Programming

Count number of occurrences for each element in List in Python

from collections import Counter

thelist = ['blue', 'red', 'blue', 'yellow', 'blue', 'red']
c = Counter(thelist)

print(c)
Output
Counter({'blue': 3, 'red': 2, 'yellow': 1})