我有三個清單。如果對象包含“HP”或“LP”,我想將列表對象附加到“過濾”列表中。輸出將所有文件名項改為“過濾”。不確定為什么會發生這種情況。您的洞察力將不勝感激!filenames = ['HP PLEAS 56s Jazz.wav', 'HP PLEAS 57s groupLaughing.wav', 'HP PLEAS 57s Guitar_2.wav', 'PLEAS 56s Jazz.wav']filtered = []original = []for x in filenames: if "LP" or "HP" in x: filtered.append(x) else: original.append(x)
1 回答

翻閱古今
TA貢獻1780條經驗 獲得超5個贊
條件 "LP" or "HP" in xalways True,相當于你的條件 : ("LP") or ("HP" in x), where ("LP")is always True,你可以使用:
for x in filenames:
if ("LP" in x) or ("HP" in x):
filtered.append(x)
else:
original.append(x)
添加回答
舉報
0/150
提交
取消