>>> import collections

>>> # Tally occurrences of words in a list
>>> cnt = collections.Counter()
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
... cnt[word] += 1
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1}) >>> c = collections.Counter('helloworld') >>> c
Counter({'l': 3, 'o': 2, 'e': 1, 'd': 1, 'h': 1, 'r': 1, 'w': 1}) >>> c.most_common(3)
[('l', 3), ('o', 2), ('e', 1)]

https://docs.python.org/2/library/collections.html

最新文章

  1. 发布Live Writer代码着色插件CNBlogs.CodeHighlighter
  2. ASP.NET MVC视图中的@Html.xxx(...)
  3. placement new讲解
  4. ubuntu sublime-text package control
  5. Android 调用系统的邮箱app发送邮件
  6. jquery and event
  7. Linux 命令 快捷命令综合
  8. POJ1163 The Triangle 【DP】
  9. 解释器模式(Interpreter)
  10. javascript 函数详解
  11. postgresql 53300错误
  12. React-Native的基本控件属性方法,对React-Native的学习,从熟悉基本控件开始。
  13. 阿里巴巴的26款超神Java开源项目!
  14. vue+vue-cli+淘宝lib-flexible做移动端自适应
  15. IdentityServer4-从数据库获取User进行授权验证(五)
  16. LeetCode-860. Lemonade Change
  17. 第 3 章 镜像 - 017 - RUN vs CMD vs ENTRYPOINT
  18. JS滚轮事件onmousewheel
  19. python learning Process and Thread.py
  20. Django中模型(一)

热门文章

  1. Data Member Order
  2. legend---八、php对象如何转换成js对象
  3. rest_framework 分页三种
  4. Metasploit的三种启动方式
  5. Linux 玩法
  6. springMVC接受前台传值
  7. 一篇文章教会你理解Scrapy网络爬虫框架的工作原理和数据采集过程
  8. [译] 我最终是怎么玩转了 Vue 的作用域插槽
  9. vue项目的环境变量
  10. Unity ContextMenu特性