python 排序并统计相同文本出现的个数
来源:互联网 发布:matlab矩阵某两行相加 编辑:程序博客网 时间:2024/06/06 19:43
#!/usr/bin/env python#Filename:readfile.pycodelist=[]f=file('input.txt','r')map={}for i in f.readlines(): i = i.strip() if map.has_key(i)==False: map.setdefault(i,1) else: count=map.get(i)+1 map[i]=countprint mapprint "\n \n"############################################ sort map ## sort map ############################################map=sorted(map.iteritems(),key=lambda asd:asd[1],reverse=True)print mapprint "\n\n"fo=file('output.txt','w')for i in map: i_list = list(i) print i_list[0] print i_list[1] fo.write(i_list[0]) fo.write("\n") fo.write(str(i_list[1])) fo.write("\n")f.close()fo.close()
0 0
- python 排序并统计相同文本出现的个数
- python 统计并排序文字出现的个数
- 【办公-WORD】VBA 统计相同字符(文字)出现的个数
- oc统计数组相同元素的个数,以及数组排序
- python统计大小写字符出现的个数
- 统计相同数字的个数
- nyoj 286 动物统计 【sort排序(统计最多相同单词的个数,不止一个)】
- python 对给定可迭代集合统计出现频率,并排序
- python 统计数组中元素出现次数并进行排序
- Python 对文本先按词频统计,若相同按字典排序,后取TopN
- 统计文本单词的个数
- Java 统计各个单词的个数并排序
- Oralce数据库查询某张表某个字段的值有相同的记录并统计个数
- python统计文本中单词个数
- python 统计文本文件中单词出现的个数
- 统计字符串中相同字符的个数
- 统计文章中相同单词的个数
- 统计数组中相同数据的个数
- 密文类型及格式帮助
- Ubuntu-配置JDK
- QML布局管理
- 移动硬盘分区(win7系统)
- Cocos2d-x3.2版本移植安卓提示'Serializing CDT Project settings..'has encountered a project
- python 排序并统计相同文本出现的个数
- 冒泡排序
- hibernate中的对象映射配置文件
- Android开发:获取屏幕宽和高的两种方法(px、dip、分辨率之间的关系及px与dip互相转化)
- iOS 自动布局
- Openwrt安装transmission离线下载
- Content Provider
- 2014,11-29
- Codefroces #279 div2 B.Queue