Cody Bable

Generation

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. if the special word is not in the string, return the special word with zero.

def word_count(str, list_special_words): dict = {} for word in list_special_words: dict[word] = str.count(word) return dict word_count('Let us go to the store and pick up the baby.', ['let', 'pick', 'baby'])

Questions about programming?Chat with your personal AI assistant