这是一种方法:
query = 'What is hello'stopwords = ['what', 'who', 'is', 'a', 'at', 'is', 'he']querywords = query.split()resultwords = [word for word in querywords if word.lower() not in stopwords]result = ' '.join(resultwords)print(result)
我注意到,如果列表中包含小写字母,您还希望删除该单词,因此我
lower()在条件检查中添加了对的调用。



