# Title: Word frequency
# Heading: Python Program to Count the Frequency of Words in a String
# Level: beginner
# Tags: word frequency, word count, dictionary, counter
# About: Counts how many times each word appears in a sentence, with a dictionary that has the words as keys and their counts as values.

def word_frequency(text):
    """How many times each word appears in text, as a dict."""
    counts = {}
    for word in text.lower().split():
        counts[word] = counts.get(word, 0) + 1
    return counts


sentence = "Red lorry yellow lorry red lorry yellow lorry"
print("Word counts:", word_frequency(sentence))
