词频统计
#e10.3Cal ThreeKingdomsimport jieba
txt=open("诊断学文件.txt",encoding='utf-8').read()
words =jieba.lcut (txt)
counts={}
for word in words :
if len(word) == 1:
continue
else:
counts = counts get (word,0) +1
items= list( counts. items())
items. sort(key=lambda x:x , reverse=True )
for i in range (15):
word ,count=items
print ("(0:<10](1:>5]"· format (word, count))
求助,为什么这个不行啊(▼皿▼#),烦死了,搞了一下午,求助大佬, 行了就有鬼了
最后一行,点号(.)打成了间隔号(·),格式化文本应该是"{0:<10}{1:>5}" 谢谢谢谢!
页:
[1]