可以使用Python中的list comprehension来解决这个问题。以下是一个示例函数:
def contains_word(lst, word):
return all(word in s for s in lst)
这个函数接受一个字符串列表lst和一个待检查的单词word,并使用all函数检查lst中的所有字符串是否都包含word。如果是,则返回True,否则返回False。
例如,如果我们有一个包含三个字符串的列表:
words = ["apple pie", "banana bread", "cherry tart"]
我们可以调用contains_word函数来检查是否所有字符串都包含单词apple:
contains_word(words, "apple") # returns True
同样,我们也可以检查是否所有字符串都包含单词blueberry:
contains_word(words, "blueberry") # returns False