0
0
HVHARIGOVIND VALSAKUMAR
PythonWordOccurence
HGV Public CookbookFunction to count the occurrences of all words in a sentence
from collections import defaultdict
def word_occurence(sentence):
occurrence = defaultdict(int)
for word in sentence.split():
occurrence[word] += 1
return occurrence