Cody Bable


generate functionMon, 03 Jul 2023

check if the word in the string is in the list of the special words to count, if so, add to dictionary along with the number of times it occurred in the string

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.'))

Questions about programming?Chat with your personal AI assistant