collections Module
时间:2010-03-29 来源:broader
collections — High-performance container datatypes
http://docs.python.org/library/collections.htmlNew in version 2.4.
This module implements high-performance container datatypes. Currently, there are two datatypes, deque and defaultdict, and one datatype factory function, namedtuple().
Changed in version 2.5: Added defaultdict.
Changed in version 2.6: Added namedtuple().
class collections.deque
- 双向队列
class collections.defaultdict([default_factory[,...]])
- default_factory, 缺省key所对应的value构建方法(注意此构建方法可以为函数方法、类实例、数据类型等等),此对象可被调用,来存储更多属于此key的value.
例如:
d=defaultdict(list),即意味着此dictionary中,每个key的value为一个list;
d=defaultdict(int),即意味着此dictionary中,每个key的value为一个int数值;
class collections.nametuple
- 顾名思义,有名称的"tuple"对象,方便以对象的方法调用tuple中的值.
相关阅读 更多 +