python练习册 每天一个小程序 第0004题
1 #-*-coding:utf-8-*-
2 __author__ = 'Deen'
3 '''
4 题目描述:任一个英文的纯文本文件,统计其中的单词出现的个数。
5 参考学习链接:
6 re http://www.cnblogs.com/tina-python/p/5508402.html#undefined
7 collections http://blog.csdn.net/liufang0001/article/details/54618484
8 '''
9 import re,collections
10 with open('english.txt','r') as fp:
11 text=fp.read().strip(',')
12 s=re.compile(r'\w+\b')
13 words=s.findall(text)
14 b=list()
15 dic=collections.defaultdict(lambda :0)
16 for word in words:
17 dic[word.lower()] +=1
18
19 print dic
20
21 '''
22 import collections,re
23 import sys
24 def cal(filename = 'english.txt'):
25 print 'now processing:' + filename + '......'
26 f = open(filename,'r')
27 data = f.read()
28 dic = collections.defaultdict(lambda :0)
29 data = re.sub(r'[\W\d]',' ',data)
30 data = data.lower()
31 datalist = data.split(' ')
32 for item in datalist:
33 dic[item] += 1
34 del dic['']
35 return dic
36 try:
37 print sorted(cal().items())
38 except:
39 print 'no input file'
40 '''
python练习册 每天一个小程序 第0004题的更多相关文章
- python练习册 每天一个小程序 第0013题
# -*-coding:utf-8-*- ''' 题目描述: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) 地址: http://tieba.baidu.com/p/21 ...
- python练习册 每天一个小程序 第0001题
1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生 ...
- python练习册 每天一个小程序 第0007题
1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但 ...
- python练习册 每天一个小程序 第0000题
PIL库学习链接:http://blog.csdn.net/column/details/pythonpil.html?&page=1 1 #-*-coding:utf-8-*- 2 __au ...
- python练习册 每天一个小程序 第0010题
# -*-coding:utf-8-*- ''' 题目描述: 使用 Python 生成类似于下图中的字母验证码图片 思路: 运用PIL库加random 随机字母进行生成 ''' import rand ...
- python练习册 每天一个小程序 第0009题
1 ''' 2 题目描述: 3 找出一个html文件中所有的url 4 5 思路 : 6 利用正则表达式进行匹配 7 8 ''' 9 10 11 import re 12 13 14 with ope ...
- python练习册 每天一个小程序 第0008题
1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 一个HTML文件,找出里面的正文. 6 7 思路: 8 利用Beautiful ...
- python练习册 每天一个小程序 第0006题
1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都 ...
- python练习册 每天一个小程序 第0005题
1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目说明: 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小 ...
随机推荐
- 帆软报表(finereport)单元格函数,OP参数
单元格模型:单元格数据和引用:数据类型.实际值与显示值.单元格支持的操作单元格样式:行高列宽.隐藏行列.自动换行.上下标.文字竖排.大文本字段分页时断开.标识说明.格式刷单元格Web属性:web显示. ...
- Java一维与二维数组的拷贝与排序
Java一维与二维数组的拷贝与排序 目录 Java一维与二维数组的拷贝与排序 Arrays.sort() 一维数组升序排序 二维数组按行升序排序 二维数组按列升序排序 Java中的数组 Java中数组 ...
- MyBatis动态SQL和缓存
1. 什么是动态SQL 静态SQL:静态SQL语句在程序运行前SQL语句必须是确定的,SQL语句中涉及的表的字段名必须是存在的,静态SQL的编译是在程序运行前的. 动态SQL:动态SQL语句是在程序运 ...
- Note/Solution -「洛谷 P6466」分散层叠算法
\(\mathcal{Description}\) Link. 给定 \(m\) 个长度为 \(n\) 的有严格升序且不包含重复元素的序列 \(a_1,a_2,\cdots,a_m\),\(q ...
- MySQL架构原理之运行机制
所谓运行机制即MySQL内部就如生产车间如何进行生产的.如下图: 1.建立连接,通过客户端/服务器通信协议与MySQL建立连接.MySQL客户端与服务端的通信方式是"半双工".对于 ...
- Vue 源码解读(5)—— 全局 API
目标 深入理解以下全局 API 的实现原理. Vue.use Vue.mixin Vue.component Vue.filter Vue.directive Vue.extend Vue.set V ...
- 【biee】BIEE启动关闭服务
转至:http://blog.sina.com.cn/s/blog_7e04e0d00101k5r8.html 版本:BIEE11g (11.1.1.6.0-11.1.1.6.7) OS:RHEL 5 ...
- ScrollView垂直滚动和HrizontalScrollView水平滚动
当我们在写一个页面,内容过多时我们需要滚动页面来查看,但是注意ScrollView下只能有一个元素,所以要把主页面改下,这样就只有一个LinearLayout元素: 1 <ScrollView ...
- PhpStudy代码执行后门
0x00 概述 只需要两个参数 Accept-Encoding: gzip,deflate Accept-Charset: Base64编码(PHP代码) 0x01 利用代码 加群可以下载:87369 ...
- 系统整理qt笔记1
main.cpp #include "mywidget.h" #include <QApplication>//包含一个应用程序类的头文件 #include <i ...