最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
统计汉字/英文单词数的python函数
时间:2012-09-10 编辑:简简单单 来源:一聚教程网
•使用正则式 "(?x) (?: [w-]+ | [x80-xff]{3} )"获得utf-8文档中的英文单词和汉字的列表。
•使用dictionary来记录每个单词/汉字出现的频率,如果出现过则+1,如果没出现则置1。
•将dictionary按照value排序,输出。
代码如下 | 复制代码 |
#!/usr/bin/python import sys def readfile(f): def divide(c, regex):
def main(): #receive files from bash #regex compile only once dict={} #get all words from files #sort dictionary by value #output to standard-output
|
可以自定义该程序。例如,
代码如下 | 复制代码 |
regex=re.compile("(?x) ( [w-]+ | [x80-xff]{3} )") |
-
下一个: python 中文分词程序实例
相关文章
- 在GD中输出汉字的函数的改进 01-12
- GD输出汉字的函数的分析 01-11
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31