优化代码 如何去除停顿词

# 方法一:暴力法,对每个词进行判断----传统方法
def remove_stopwords1(text):
    words = text.split(' ')
    new_words = list()
    for word in words:
        if word not in stopwords:
            new_words.append(word)
    return new_words

# 方法二:先构建停用词的映射---推荐方法
for word in stopwords:
    if word in words_count.index:
        words_count[word] = -1

def remove_stopwords2(text):
    words = text.split(' ')
    new_words = list()
    for word in words:
        if words_count[word] != -1:
            new_words.append(word)
    return new_words
原文地址:https://www.cnblogs.com/cupleo/p/11425098.html