【发布时间】:2011-03-31 11:08:42
【问题描述】:
对不起,如果问题有点混乱。这类似于this question
我认为上述问题与我想要的很接近,但在 Clojure 中。
有another问题
我需要这样的东西,但不是那个问题中的“[br]”,而是需要搜索和删除的字符串列表。
希望我说清楚了。
我认为这是因为python中的字符串是不可变的。
我有一个需要从字符串列表中删除的干扰词列表。
如果我使用列表推导,我最终会一次又一次地搜索相同的字符串。所以,只有“of”被删除,而不是“the”。所以我修改后的列表是这样的
places = ['New York', 'the New York City', 'at Moscow' and many more]
noise_words_list = ['of', 'the', 'in', 'for', 'at']
for place in places:
stuff = [place.replace(w, "").strip() for w in noise_words_list if place.startswith(w)]
我想知道我犯了什么错误。
【问题讨论】:
-
你没有说清楚;在此处陈述您的问题,然后如果您认为有必要,请在下方提供具有相似答案的类似问题的链接。
标签: python regex list-comprehension stop-words