用python实现统计字符串中字母的个数 txt = input("请输入字符串:") counts = {} for t in txt: counts[t] = counts.get(t,0) + 1 ls = list(counts.items()) ls.sort(key=lambda x:x[1],reverse=True) for i in range(len(ls)): t,c = ls[i] print("{0:<10}{1:>5}".format(t,c))