在Python中,可以通过以下几种方式筛选出想要的词汇:
words = ["apple", "banana", "cherry", "durian"]
filtered_words = []
for word in words:
if "a" in word:
filtered_words.append(word)
print(filtered_words) # 输出:['apple', 'banana']
words = ["apple", "banana", "cherry", "durian"]
filtered_words = [word for word in words if "a" in word]
print(filtered_words) # 输出:['apple', 'banana']
words = ["apple", "banana", "cherry", "durian"]
filtered_words = list(filter(lambda word: "a" in word, words))
print(filtered_words) # 输出:['apple', 'banana']
以上三种方法都可以根据具体的需求来进行筛选出想要的词汇。可以根据实际情况选择最适合的方式。