python中的Collections模块之Counter

虽然工作中常用Python,但都是些基本操作,对于这种高阶的工具包,一直是只知道有那么个东西,没调用过,每次都是自己造轮子。

10年积累的成都做网站、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有松溪免费网站建设让你可以放心的选择与我们合作。

人生苦短, 我用Python,为毛还重复造轮子,装什么C呢。

看下collections的init

__all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList',
'UserString', 'Counter', 'OrderedDict', 'ChainMap']

挑个今天眼热的模块,开始鼓捣鼓捣。

一、Counter

  猜名字,是跟计数有关的玩意儿

  看源码中类的介绍

 1 class Counter(dict):
 2     '''Dict subclass for counting hashable items.  Sometimes called a bag
 3     or multiset.  Elements are stored as dictionary keys and their counts
 4     are stored as dictionary values.'''

分享文章:python中的Collections模块之Counter
文章分享:http://scjbc.cn/article/dsojcgo.html

其他资讯