忽略大小写
以降序形式输出
!!!!!!重要的两句!!!!!!:
items=list(f.items())##f为字典,字典转列表
items.sort(key=lambda x:x[1],reverse=True)###以第二列排序
完整代码:
s="wopqjfioI'''765456789UGLFFDUUTKMUUGuigqefhowdjioueyrtuwfevsjcabxhniuwqdoefpoqlknbcahjwqdgfuedc"
f={}
s=s.lower()
for i in s:
if i.isalpha()==True:
if i in f :
f[i]+=1
else:
f[i]=1
items=list(f.items())
items.sort(key=lambda x:x[1],reverse=True)
print(items)
运行结果:
==== RESTART: C:\Users\LENOVO\Desktop\practice.py ====
[('u', 10), ('f', 7), ('o', 6), ('w', 5), ('q', 5), ('i', 5), ('d', 5), ('e', 5), ('j', 4), ('g', 4), ('h', 3), ('c', 3), ('p', 2), ('l', 2), ('t', 2), ('k', 2), ('a', 2), ('b', 2), ('n', 2), ('m', 1), ('y', 1), ('r', 1), ('v', 1), ('s', 1), ('x', 1)]