from collections import Counter import re with open('a.txt', 'r', encoding='utf-8') as f: txt = f.read() c = Counter(re.split('W+',txt)) #取出每个单词出现的个数 print(c) ret = c.most_common(10) #取出频率最高的前10个 print(ret)