Q:

Write a Python program to count the occurrences of each word in a given sentence

0

Write a Python program to count the occurrences of each word in a given sentence

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def word_count(str):
    counts = dict()
    words = str.split()

    for word in words:
        if word in counts:
            counts[word] += 1
        else:
            counts[word] = 1

    return counts

print( word_count('the quick brown fox jumps over the lazy dog.'))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now