Cody Bable


generate functionMon, 03 Jul 2023

count the number of words in a sentence that occur in the special words list

def count_special_words(sentence, special_words): special_words = ["your", "words", "here"] special_words = [word.lower() for word in special_words] sentence_words = sentence.lower().split() count = 0 for word in sentence_words: if word in special_words: count += 1 return count count_special_words("Hello, this is a sentence!", ["hello", "this"])

Questions about programming?Chat with your personal AI assistant