我就这样做:from nltk.corpus import stopwords
s=set(stopwords.words('english'))
txt="a long string of text about him and her"
print filter(lambda w: not w in s,txt.split())
哪个指纹['long', 'string', 'text']
如果您认为散列集查找是O(1),那么在复杂度方面,字符串中的单词数应该是O(n)。
FWIW,我的NLTK版本定义了127stopwords:'all', 'just', 'being', 'over', 'both', 'through', 'yourselves', 'its', 'before', 'herself', 'had', 'should', 'to', 'only', 'under', 'ours', 'has', 'do', 'them', 'his', 'very', 'they', 'not', 'during', 'now', 'him', 'nor', 'did', 'this', 'she', 'each', 'further', 'where', 'few', 'be