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

def word_count(special_words, string): words = string.split() special_word_counts = dict() for word in words: if word in special_words: if word in special_word_counts: special_word_counts[word] = special_word_counts[word] + 1 else: special_word_counts[word] = 1 return special_word_counts word_count(['apple', 'banana', 'grape'], "one fish two fish apple grape grape banana fish")

Want to kickstart your project?Use the new AI Studio to create your code