我正在编写一个函数,该函数采用 in_file 并检查该文件中字母的频率并以这种格式(字母:频率)写入 out_file。这是我到目前为止所得到的任何人都可以帮忙吗?
def count_letters(in_file,out_file):
in_file = open(in_file,"r")
out_file = open(out_file,"w")
for line in in_file:
words = line.split()
for word in words:
for letter in word:
print(letter,':',line.count(letter),file=out_file,end="\n")