jieba分词——聊斋志异

代码:

import jieba
print("====学号:202031013040====")
txt=open("聊斋志异.txt","r",encoding="gb18030")
words=jieba.lcut(txt.read())
counts={}
for word in words:
if len (word)==1:
continue
else:
counts[word]=counts.get(word,0)+1
item=list(counts.items())
item.sort(key=lambda x:x[1],reverse=True)
for i in range(20):
print("{0:<10}{1:>5}".format(item[i][0],item[i][1]))

运行结果:

jieba分词——聊斋志异

 

上一篇:基于知识图谱的问答系统(protege,jena,jieba分词的结合)


下一篇:大型数据库的应用项目之基于中文新闻分词绘制词云图