python去除停用词(结巴分词下)

python 去除停用词  结巴分词


 

import jieba

#stopwords = {}.fromkeys([ line.rstrip() for line in open('stopword.txt') ])

stopwords = {}.fromkeys(['的', '附近'])

segs = jieba.cut('北京附近的租房', cut_all=False)
final = ''
for seg in segs:
    seg = seg.encode('gbk')
    if seg not in stopwords:
            final += seg
print final

posted @ 2015-11-10 15:20  xiaoli2018  阅读(27012)  评论(0编辑  收藏  举报