一点点缩进和变化周围的变量将解决您的问题
for wine in wines:
glass=wine #Lets pour your wine in a glass
for stop in stop_words:
if stop in glass: #Is stop in your glass?
#Replace stop in glass and pour it in the glass again
glass = glass.replace(stop, "")
result.append(glass) #Finally pour the content from your glass to result
result
[' Chardonnay', 'Cabernet Sauvignon ', 'Bordeaux ']如果你想冒险,你可以使用正则表达式。我相信在这种情况下,正则表达式可能比简单的循环更快
>>> for wine in wines:
result.append(re.sub('('+'|'.join(stop_words)+')','',wine))
>>> result
[' Chardonnay', 'Cabernet Sauvignon ', 'Bordeaux ']
>>>或者将其作为列表理解
>>> [re.sub('('+'|'.join(stop_words)+')','',wine) for wine in wines]
[' Chardonnay', 'Cabernet Sauvignon ', 'Bordeaux ']
>>>