How to get item frequency count in Python?

Sometimes, we want to get item frequency count in Python.

In this article, we’ll look at how to get item frequency count in Python.

How to get item frequency count in Python?

To get item frequency count in Python, we can use the Counter class.

For instance, we write

from collections import Counter

words = "apple banana apple strawberry banana lemon"
c = Counter(words.split())

to split the words in words with split.

Then create a Counter object with the list of strings split from words to get an object with the count of each word.

Conclusion

To get item frequency count in Python, we can use the Counter class.