|
发表于 2020-5-8 17:16:40
From FishC Mobile
|
显示全部楼层
|阅读模式
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#e10.3Cal ThreeKingdoms
import jieba
txt=open("诊断学文件.txt",encoding='utf-8').read()
words =jieba.lcut (txt)
counts={}
for word in words :
if len(word) == 1:
continue
else:
counts [word]= counts get (word,0) +1
items= list( counts. items())
items. sort(key=lambda x:x[1] , reverse=True )
for i in range (15):
word ,count=items [i]
print ("(0:<10](1:>5]"· format (word, count))
求助,为什么这个不行啊(▼皿▼#),烦死了,搞了一下午,求助大佬,
行了就有鬼了
最后一行,点号(.)打成了间隔号(·),格式化文本应该是"{0:<10}{1:>5}"
|
|