AnswerBox
Python

Word Count in a String

Description:
Count the frequency of each word in a sentence.
Python Code
from collections import Counter

sentence = "the cat sat on the mat and the cat"
words = sentence.split()
freq = Counter(words)
for word, count in freq.items():
    print(word + ": " + str(count))
Expected Output
the: 3, cat: 2, sat: 1 ...