统计高频词

匿名 (未验证) 提交于 2019-12-03 00:37:01
#返回高频词 def word(file):     with open(file) as file:         data = file.read()  #一次性读取全部的内容         contents = re.findall('\w+',data) #匹配所有的字符         count = {}         for content in contents:             count[content] = count.get(content,0) + 1  #如果 count里面没有content则会设置成0 然后加1         print(count)         sortedcount = sorted(count.items(),key = operator.itemgetter(1)) #排序 1 表示按照 values排         print(sortedcount[-1][0])

文章来源: 统计高频词
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!