#count对象 Only 2.7
from collections import Counter
#统计字母出现的次数
Counter('hello world')
Counter(['red', 'blue', 'red', 'green', 'blue', 'blue']) #小于等于0的会被忽略
c = Counter(a=4, b=2, c=0, d=-2)
list(c.elements())
#取前三个最多的字母
Counter('hello world').most_common(3) #堆
from collections import deque
d = deque('abc')
d.append('d')
d.pop() #后入先出
d.popleft() #先入先出 #返回最后n行文本
deque(open(filename), n) #defaultdict
from collections import defaultdict
#使用list初始化一个dict
d = defaultdict(list)
d["yellow"].append(1)
d["red"].append(2)
d["yellow"].append(3) print d.items() #[('red', [2]), ('yellow', [1, 3])]
#用int初始华一个dict
d = defaultdict(int)
d["yellow"] += 1
d["red"] += 2
d["yellow"] += 3
print d.items() #[('red', 2), ('yellow', 4)]

最新文章

  1. Xcode清除缓存、清理多余证书
  2. JavaScript的DOM操作。Window.document对象
  3. Using HiveServer2 - Authentication
  4. Arduino+RFID RC522 +继电器
  5. BNUOJ-26580 Software Bugs KMP匹配,维护
  6. android SurfaceView绘制 重新学习--切图clipRect详解
  7. 关于配置ST_Geometry报ORA-06522的问题
  8. 转 gl_VertexID的含义
  9. 四则运算GUI
  10. PHP-无限级分类(迭代法创建)
  11. Servle第四篇(会话技术之cookie)
  12. POJ1062昂贵的聘礼(经典) 枚举区间 +【Dijkstra】
  13. shell 的条件表达式及逻辑操作符简单介绍
  14. Spring注解之@Retention
  15. MySQL Partition--分区基础
  16. 十年百度工作心得(月薪75k)
  17. PSP(3.13——3.15)以及周记录
  18. 图片 和 base64 互转
  19. linux上的mysql配置过程
  20. C# 基础备忘录

热门文章

  1. 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(二)
  2. 输入框获取焦点后placeholder文字消失、修改placeholder的样式
  3. AutoResetEvent的使用介绍(用AutoResetEvent实现同步)
  4. linux 进程间通信机制(IPC机制)一总览
  5. GetTop(),GetTopLeft()等等
  6. ASP.NET-GridView之表头设计
  7. hdu1403(后缀数组模板)
  8. kuangbin专题16D(next求最小循环节)
  9. RouteSelector的初始化
  10. Mysql 别名