Java教程

jieba分词——聊斋志异

本文主要是介绍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分词——聊斋志异的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!