Write a program to compute the count of each word in a sentence and print it


Topic: Write a program to compute the count of each word in a sentence and print it

Solution

word_freq = {}
line = 'how many how words does this many have'
for word in line.split():
   word_freq[word] = word_freq.get(word, 0) + 1
print(word_freq)



List all Python Programs