我试图从字符串列表中的每个元素中去除子字符串。我无法弄清楚如何处理具有多个要删除的子字符串(停用词)的字符串的情况。
wines = ("2008 Chardonnay", "Cabernet Sauvignon 2009", "Bordeaux 2005 Cotes du Rhone")
stop_words = ("2005", "2008", "2009", "Cotes du Rhone")
result = []
for wine in wines:
for stop in stop_words:
if stop in wine:
x = wine.replace(stop, "")
result.append(x)
print result
将 if 语句更改为 for 或 while 会返回垃圾或挂起。有什么建议吗?