How to remove list of words from a list of strings

后端 未结 4 782
情深已故
情深已故 2020-12-13 11:19

Sorry if the question is bit confusing. This is similar to this question

I think this the above question is close to what I want, but in Clojure.

There is a

4条回答
  •  天涯浪人
    2020-12-13 11:57

    >>> import re
    >>> noise_words_list = ['of', 'the', 'in', 'for', 'at']
    >>> phrases = ['of New York', 'of the New York']
    >>> noise_re = re.compile('\\b(%s)\\W'%('|'.join(map(re.escape,noise_words_list))),re.I)
    >>> [noise_re.sub('',p) for p in phrases]
    ['New York', 'New York']
    

提交回复
热议问题