def check_letter_frequency():
fhand = open('phil.txt')
letter_frequency_dict = dict()
for wordz in fhand:
wordz = wordz.lower()
words = wordz.strip()
for letter in words:
if letter in letter_frequency_dict:
letter_frequency_dict[letter] += 1
else:
letter_frequency_dict[letter] = 1
sorted_letter_frequency = [(key, letter_frequency_dict[key]) for key in sorted(letter_frequency_dict, key=letter_frequency_dict.get, reverse=True)]
print("letter frequency of:")
letters = []
from string import ascii_lowercase
for key, value in sorted_letter_frequency[:8]:
# letters.append(ley)
print('{} : {}'.format(key, value))
check_letter_frequency()
我的输出如下所示:
letter frequency of: : 182 e : 108 t : 91 o : 77 h : 67 n : 66 i : 64 a : 64
陪伴而非守候
狐的传说
相关分类