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]: mydequ
1164
e.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学习笔记(三十三)常用内置模块(2)collections_namedtuple_deque_defaultdict_OrderedDict_Counter
- Python提供了以下几个内置tools模块:operator collections itertools functools
- python 内置模块:collections
- Python系列之Collections内置模块(2)
- Python系列之Collections内置模块(2)
- Python的collections模块及namedtuple详解
- Python中内置的日志模块logging用法详解
- 使用python的内置ctypes模块与c、c++写的dll进行交互
- 使用python内置smtplib模块发送邮件
- Python 模块collections
- 使用Python内置的模块与函数进行不同进制的数的转换
- python collections 模块
- Python_内置模块
- Python的collections模块中namedtuple结构使用示例
- Python常用模块re,collections,random
- Python17个常用内置模块总结
- python的常用模块之collections模块详解
- Python中Collections模块的Counter容器类使用教程
- python 内置的os模块将文件夹下所有图片名称加上指定字符
- python的内置模块