programming-examples/python/_Basics/Python program to count the occurrences of each word in a given sentence.py

13 lines
313 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
def word_count(str):
counts = dict()
words = str.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts
print( word_count('the quick brown fox jumps over the lazy dog.'))