在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']
以上三種方法都可以根據具體的需求來進行篩選出想要的詞匯。可以根據實際情況選擇最適合的方式。