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.