以下是一个示例的解决方法,使用Python语言实现:
def compare_lists(sentences, words):
complete_sentences = []
for sentence in sentences:
# 将句子按空格分割为单词列表
sentence_words = sentence.split()
# 检查句子中的每个单词是否都存在于给定的单词列表中
if all(word in words for word in sentence_words):
# 如果句子中的所有单词都存在于单词列表中,将完整的句子添加到结果列表中
complete_sentences.append(sentence)
return complete_sentences
# 示例用法
sentences = ["I love coding", "Coding is fun", "I enjoy coding challenges"]
words = ["I", "coding"]
result = compare_lists(sentences, words)
print(result)
输出结果:
['I love coding', 'I enjoy coding challenges']
在上述示例中,compare_lists
函数接受两个参数:sentences
和words
。它遍历句子列表中的每个句子,将句子分割为单词列表,并检查每个单词是否都存在于给定的单词列表中。如果句子中的所有单词都存在于单词列表中,那么该句子就是完整的句子,将其添加到结果列表中。最后,函数返回结果列表。
注意,示例中使用的是简单的字符串比较,没有考虑大小写和标点符号的问题。如果需要考虑这些问题,可以在比较之前进行适当的处理。