How to count the number of occurrences for each item in a list with Python

1 Answer

0 votes
from collections import Counter

lst = ["python", "php", "php", "c++", "php", "c++", "java"]

result = Counter(lst)

print(result)


'''
run:

Counter({'php': 3, 'c++': 2, 'python': 1, 'java': 1})

'''

 



answered Nov 23, 2018 by avibootz

Related questions

2 answers 232 views
7 answers 862 views
1 answer 180 views
1 answer 138 views
1 answer 206 views
1 answer 154 views
...