标签:com 分享 编码 port pen lam ext ace key
中文分词
import jieba fo=open(‘book.txt‘,‘r‘,encoding=‘utf-8‘) s=fo.read() fo.close() for i in ‘,。!"‘: s=s.replace(i,‘ ‘) words=jieba.cut(s) a=list(words) exp={‘,‘,‘的‘,‘也是‘,‘不过‘,‘好的‘} key=set(a)-exp dic={} for w in key: if len(w)>1: dic[w]=a.count(w) wx=list(dic.items()) wx.sort(key=lambda x:x[1],reverse=True) for i in range(15): print(wx[i])
标签:com 分享 编码 port pen lam ext ace key
原文地址:http://www.cnblogs.com/lqx12/p/7610391.html