标签:div com pen enc nbsp with open 单词 txt from
统计一篇英文文章内每个单词出现频率,并返回出现频率最高的前10个单词及其出现次数
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)
统计一篇英文文章内每个单词出现频率,并返回出现频率最高的前10个单词及其出现次数
标签:div com pen enc nbsp with open 单词 txt from
原文地址:https://www.cnblogs.com/jiangshanduojiao/p/9381306.html