赞
踩
# 中文
txt = input("请输入一段文本:")
d = {}
for i in txt:
d[i] = d.get(i, 0) + 1 # 字典中的值
ls = list(d.items())
ls.sort(key=lambda x: x[1], reverse=True) # 排序
for i in range(len(d)):
word, count = ls[i]
print("{:<10}{:<5}".format(word, count))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。