关于slice.indices() >>> help(slice) Help on class slice in module builtins: class slice(object) | slice(stop) # 如果只有一个参数,那么参数表示为结束的下标 | slice(start, stop[, step]) # 如果有两个参数,那么代表开始下标和结束下标 ..... indices()的使用,能够从新定义截取的最大长度 >>> a 'HelloWorld!!
Counter是dict的子类,所以它其实也是字典.只不过它的键对应的值都是计数,值可以是任意整数.下面是四种创建Counter实例的例子: >>> c = Counter() # a new, empty counter >>> c = Counter('gallahad') # a new counter from an iterable >>> c = Counter({'red': 4, 'blue': 2}) # a new counter
collections collections是Python数据类型的补充,可以实现Counter计数.可命名元组(namedtuple).默认字典.有序字典.双向队列等功能 参考:http://python.usyiyi.cn/python_278/library/collections.html Help on module collections: NAME collections FILE c:\python27\lib\collections.py CLASSES __builtin_
Table of Contents 1. class collections.Counter([iterable-or-mapping]) 1.1. 例子 1.2. 使用实例 2. To Be Continued class collections.Counter([iterable-or-mapping]) Counter 是实现的 dict 的一个子类,可以用来方便地计数. 例子 举个计数的例子,需要统计一个文件中,每个单词出现的次数.实现方法如下 # 普通青年 d = {} with op