CodShot
Python Public

Count Word Frequency

Count how often each word appears in a short text.

#python #string #dictionary #beginner
Python
text = "python is fun and python is useful"
words = text.lower().split()

counts = {}

for word in words:
    counts[word] = counts.get(word, 0) + 1

for word, count in counts.items():
    print(word, count)

Notes

This version is intentionally simple. For larger tasks, collections.Counter is also a good option.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support