python 内置模块collections
1、namedtuple
from collections import namedtuple
websites = [
(‘Sohu’, ‘http://www.google.com/’, u’张朝阳’),
(‘Sina’, ‘http://www.sina.com.cn/’, u’王志东’),
(‘163’, ‘http://www.163.com/’, u’丁磊’)
]
Website = namedtuple(‘Website’, [‘name’, ‘url’, ‘founder’])
mywebsite = Website(‘ading’, ‘http://blog.65535.fun’, u’林天来’)
print(mywebsite.name)
print(mywebsite.url)
print(mywebsite.founder)
for website in websites:
website = Website._make(website)
print website
2、deque
In [1]: from collections import deque
In [2]: mydeque = deque(maxlen=10)
In [3]: mydeque.maxlen
Out[3]: 10
In [4]: mydeque.append(1)
In [5]: mydeque.append(10)
In [6]: mydeque
Out[6]: deque([1, 10])
In [7]: mydeque.appendleft(‘a’)
In [8]: mydeque.appendleft(‘b’)
In [9]: mydeque
Out[9]: deque([‘b’, ‘a’, 1, 10])
In [10]: mydeque.pop()
Out[10]: 10
In [11]: mydeque
Out[11]: deque([‘b’, ‘a’, 1])
In [12]: mydeque.popleft()
Out[12]: ‘b’
In [13]: mydeque
Out[13]: deque([‘a’, 1])
deque 还有常用的方法 :copy,reverse, insert, clear
- python 内置模块collections
- python3 内置模块collections.deque(双向队列)的用法
- Python学习笔记(三十三)常用内置模块(2)collections_namedtuple_deque_defaultdict_OrderedDict_Counter
- Python提供了以下几个内置tools模块:operator collections itertools functools
- python 内置模块:collections
- Python系列之Collections内置模块(2)
- Python系列之Collections内置模块(2)
- Python collections 模块用法举例
- Python中的内置模块和第三方模块
- 转 python内置正则表达式(re)模块官方文档简要中文版
- Python 之 统计模块collections
- Python内建模块--collections
- Python17个常用内置模块总结 (运维)
- python基础之collections模块
- python内置模块~shutil
- python 内置标准库socketserver模块的思考
- Python:collection模块(内置了一些群集相关的方法和函数)
- Python第五章__模块介绍,常用内置模块
- Python3.5——内置模块详解之time与datetime模块
- python 常用的内置模块使用