Using collections.Counter for Frequency Counting in Python


Count the occurrences of items in a collection.

Source Code

from collections import Counter
words = ["apple", "banana", "apple", "pear", "banana", "orange", "banana"]
word_counts = Counter(words)
print(word_counts)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments