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 265 views
7 answers 951 views
1 answer 199 views
1 answer 164 views
1 answer 238 views
1 answer 182 views
...