统计十篇文档各个英语单词出现次数 用python 我最近自学了 可结果有问题 求解释!

如题所述

from collections import Counter


def readit(fname):
    with open(fname) as f:
        return f.read()
        
s = ''.join([readit(f'D:\\{i}.txt') for i in range(1, 11)])
for word, count in Counter(s.split()).most_common():
    print(word, count)

If you want to know the usage of `Counter`, try `from collections import Counter;help(Counter)` at python idle.

温馨提示:答案为网友推荐,仅供参考
相似回答