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,word,item,words,counts,txt,分词,聊斋志异 来源: https://www.cnblogs.com/i3wood/p/15677672.html