txt = input("请输入一段英文文本:")
txt = txt.lower()
d = {}
for i in txt:
if i in "abcdefghijklmnopqrstuvwxyz":
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))
本博客介绍了一种使用Python进行英文文本统计分析的方法,通过将输入的文本转换为小写并利用字典数据结构来计数每个字母出现的次数,最后按字母出现频率排序输出结果。





