热门

最新

红包

立Flag

投票

同城

我的

发布
a2005426
a2005426
2 年前
truea2005426

from collections import Counter

with open('sample.txt', 'r') as f:
text = f.read().lower()

counter = Counter(c for c in text if c.isalpha())
total_chars = sum(counter.values())

with open('result.txt', 'w') as f:
f.write(f'共{total_chars}个字符,其中每个字母的分布情况为:\n')
for char, count in sorted(counter.items()):
f.write(f'{char}:{count}, ')

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条动态
立即登录