python从文本文件中选出使用频率最多的单词,,[Python]代码Py
python从文本文件中选出使用频率最多的单词,,[Python]代码Py
[Python]代码
Python语言: python.从一个文本文件中选出使用频率最多的若干个单词#coding:utf-8# ------------------------------------------------------------# 简介 : 从一个文件中选出使用频率最多的10个单词# 请自行准备一个 test.txt 文档放在与本脚本相同目录# 更新 : 2008年6月27日# ------------------------------------------------------------from time import timefrom operator import itemgetterdef test(): # 取 10 个,有需要可以修改, 及定义读取的文件 test.txt iList = 10 strFileName = 'test.txt' count = {} for word in open(strFileName).read().split(): if count.has_key(word): count[word] = count[word] + 1 else: count[word] = 1 print sorted(count.iteritems( ), key=itemgetter(1), reverse=True)[0:iList]# 调用if __name__ == '__main__': t1 = time() test() print time()-t1
相关内容
- python修改Windows注册表切换ie代理,pythonie,[Python]代码#
- python实现独身模式,python实现独身,class A:
- Python使用Decorator实现独身模式,pythondecorator,下面是要求
- Gmail 发信,gmail发信,Python语言: Gm
- Python 将DOC word文档转换为PDF,,下面代码只能在windo
- python遍历目录树代码,python历目录树,from os.path
- Python 发email 带附件,python发email附件,Python 发emai
- python的日志logging模块使用总结,pythonlogging,1.简单的将
- python 判断操作系统类型代码,python操作系统,有时候需
- 使用python生成随机密码的例子,python生成例子,import r
评论关闭