python统计汉字词频
来源:互联网 发布:阿里云个人邮箱登录 编辑:程序博客网 时间:2024/05/22 13:11
# -*- coding: utf-8 -*-"""Created on Tue Apr 22 17:25:47 2014@author: lifeix"""import sys,re reload(sys) sys.setdefaultencoding('utf8') txt = open('/home/lifeix/xiaoshuo1.txt','r').read() wfile=open('/home/lifeix/result.txt','w') r = re.compile('[\x80-\xff]+') m = r.findall(txt) dict={} z1 = re.compile('[\x80-\xff]{3}') z2 = re.compile('[\x80-\xff]{4}') z3 = re.compile('[\x80-\xff]{6}') z4 = re.compile('[\x80-\xff]{8}') for i in m: x = i.encode('utf8') i = z1.findall(x) for j in i: if (j in dict): dict[j]+=1 else: dict[j]=1 dict=sorted(dict.items(), key=lambda d:d[1],reverse=True) for a,b in dict: if b>0: wfile.write(a+','+str(b)+'\n') wfile.close() f = open('/home/lifeix/result.txt','r')count = 0for line in f.readlines(): if count%10 == 0: print '\n' line = line[0:len(line) - 1] print "%s "%line, count = count + 1f.close()
0 0
- python统计汉字词频
- python 统计词频
- python 统计词频
- python统计文档词频
- Python新闻联播词频统计
- python词频统计
- Python 中的词频统计
- 【python技能】词频统计
- 词频统计python
- Python进行词频统计
- python统计词频的方法
- WordsCount(词频统计)-Python语言编写!
- Python实现中文小说词频统计
- python--10行代码搞定词频统计
- python--更干净的词频统计
- python 文本单词提取和词频统计
- Python使用Hadoop进行词频统计
- Python分词并进行词频统计
- 一个小问题。
- jquery的ajax请求与springMVC交互
- 什么是反向代理?
- 使用js判断是手机访问还是电脑访问
- 获取屏幕尺寸大小和密度
- python统计汉字词频
- struts2+spring+hibernate整合
- JAVA基础---数组的创建及遍历
- Visual Assist 10.8
- RHEL等Linux系统使用wpa_supplicant以WPA-PSK/WPA2-PSK连接WIFI
- poj 2762 Going from u to v or from v to u?
- hunnu11323(在n个点中,选择两个使得它们之间的距离最大)
- 教你透彻理解红黑树
- sizeof 操作符(c++primer)