sarathkaul on 171119 modified by arkadip bhattacharyadarkmatter18 on 20042020 from collections import counter sentence a b a b c b d b d e f e g e h e i e j e 0 occurencedict wordoccurrencesentence alloccurencedictword count for word count in countersentence split items true dictwordoccurrencetwo spaces two 1 spaces 1 creating a dictionary containing count of each word sarathkaul on 17 11 19 modified by arkadip bhattacharya darkmatter18 on 20 04 2020 from collections import counter sentence a b a b c b d b d e f e g e h e i e j e 0 occurence_dict word_occurrence sentence all occurence_dict word count for word count in counter sentence split items true dict word_occurrence two spaces two 1 spaces 1 creating a dictionary containing count of each word
from collections import defaultdict


def word_occurrence(sentence: str) -> dict:
    
    occurrence: defaultdict[str, int] = defaultdict(int)
    
    for word in sentence.split():
        occurrence[word] += 1
    return occurrence


if __name__ == "__main__":
    for word, count in word_occurrence("INPUT STRING").items():
        print(f"{word}: {count}")