Run

Count words with a dictionary in Python

Count how often each word appears. Press Run to try it, then change the code and run it again.

main.py

from collections import Counter

text = "the quick brown fox jumps over the lazy dog the end"
counts = Counter(text.split())

for word, count in counts.most_common(3):
    print(f"{word}: {count}")
Output

Press Run to see the output.

More Python examples

Open the full Python online compiler →