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题的更多相关文章

  1. python练习册 每天一个小程序 第0013题

    # -*-coding:utf-8-*- ''' 题目描述: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) 地址: http://tieba.baidu.com/p/21 ...

  2. python练习册 每天一个小程序 第0001题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生 ...

  3. python练习册 每天一个小程序 第0007题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但 ...

  4. python练习册 每天一个小程序 第0000题

    PIL库学习链接:http://blog.csdn.net/column/details/pythonpil.html?&page=1 1 #-*-coding:utf-8-*- 2 __au ...

  5. python练习册 每天一个小程序 第0010题

    # -*-coding:utf-8-*- ''' 题目描述: 使用 Python 生成类似于下图中的字母验证码图片 思路: 运用PIL库加random 随机字母进行生成 ''' import rand ...

  6. python练习册 每天一个小程序 第0009题

    1 ''' 2 题目描述: 3 找出一个html文件中所有的url 4 5 思路 : 6 利用正则表达式进行匹配 7 8 ''' 9 10 11 import re 12 13 14 with ope ...

  7. python练习册 每天一个小程序 第0008题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 一个HTML文件,找出里面的正文. 6 7 思路: 8 利用Beautiful ...

  8. python练习册 每天一个小程序 第0006题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都 ...

  9. python练习册 每天一个小程序 第0005题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目说明: 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小 ...

随机推荐

  1. JDBC加强

    一.使用PreparedStatement预编译语句防止SQL注入 什么是SQL注入? 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行 ...

  2. 框架5--nginx安装部署 上(web服务)

    目录 框架5--nginx安装部署(web服务) 1.练习 2.昨日问题 3.今日内容 4.什么是web服务 5.web服务器软件 6.部署Nginx 7.平滑增加Nginx模块 8.Nginx的命令 ...

  3. C#动态规划法计算文本相似度

    C# 采用动态规划算法,计算两个字符串之间的相似程度. public static double CountTextSimilarity(string textX, string textY, boo ...

  4. etcd受损节点重新加入集群

    文章目录 查看当前集群状态 删除受损etcd节点的数据 数据受损节点重新加入集群 修改etcd启动参数,重启etcd 由于自己的误操作,将A节点的etcd备份数据复制到B节点的etcd备份节点目录下, ...

  5. 今天你花里胡哨了吗 --- 定制属于自己的linux ssh迎宾信息

    请开始你的表演 linux-oz6w:~ # cat << 'eof' > /etc/profile.d/ssh-login-info.sh #!/bin/sh # 输出一个图像 e ...

  6. c++ struct enum union加typedef与不加typedef

    struct/enum/union加typedef与不加typedef 匿名结构体 struct { int a; int b; } v; // 这里表示定义了一个结构体的变量v,且结构体类型没有名字 ...

  7. AQS源码二探-JUC系列

    本文已在公众号上发布,感谢关注,期待和你交流. AQS源码二探-JUC系列 共享模式 doAcquireShared 这个方法是共享模式下获取资源失败,执行入队和等待操作,等待的线程在被唤醒后也在这个 ...

  8. C#异步编程由浅入深(三)细说Awaiter

      上一篇末尾提到了Awaiter这个类型,上一篇说了,能await的对象,必须包含GetAwaiter()方法,不清楚的朋友可以看上篇文章.那么,Awaiter到底有什么特别之处呢?   首先,从上 ...

  9. 面试题(造火箭必备技能):请举例一个最有成就感的性能bug

    当前,绝大部分招聘都有性能要求或者把其作为加分项(会性能优先),哪怕你不是面试的性能,面试的时候可能会问性能,所以大家才会有"面试造火箭,进去拧螺丝"的共鸣.至于企业为什么重视性能 ...

  10. 使用教程:宝塔服务器管理助手Linux面版

    网页提示:宝塔Linux面板初始化成功,点击登陆页面:直接使用初始化配置时填写的帐号及密码登陆面板功能:网站管理.FTP管理.数据库管理.系统安全.文件管理.计划任务.环境设置. 方法/步骤1: 使用 ...