import string
d = {}
def choice(str):
s = str.lower() #全部转化为小写
for c in range(97,123): #ASCII 97-122
for i in chr(c): #ASCII 转化为字符
d[i] = s.count(i) #统计s中出现'i'的次数
print(d)
with open('test','r') as f:
choice(f.read())
用python统计文件中各个单词出现的次数
最新推荐文章于 2022-11-19 23:26:56 发布