Python Deque 模块使用详解
2014-07-04 10:14
676 查看
创建Deque序列:
from collections import deque d = deque()
Deque提供了类似list的操作方法:
d = deque() d.append('1') d.append('2') d.append('3') len(d) d[0] d[-1]
输出结果:
3 '1' '3'
两端都使用pop:
d = deque('12345') len(d) d.popleft() d.pop() d
输出结果:
5 '1' '5' deque(['2', '3', '4'])
我们还可以限制deque的长度:
d = deque(maxlen=30)
当限制长度的deque增加超过限制数的项时, 另一边的项会自动删除:
d = deque(maxlen=2) d.append(1) d.append(2) d d.append(3) d deque([1, 2], maxlen=2) deque([2, 3], maxlen=2)
添加list中各项到deque中:
d = deque([1,2,3,4,5]) d.extendleft([0]) d.extend([6,7,8]) d
输出结果:
deque([0, 1, 2, 3, 4, 5, 6, 7, 8])
您可能感兴趣的文章:
相关文章推荐
- Burp Suite详细使用教程-Intruder模块详解
- 【转】Burp Suite详细使用教程-Intruder模块详解
- Burp Suite详细使用教程-Intruder模块详解
- Python中的ConfigParser模块使用详解
- NDK使用静态库模块组织代码详解
- Struts实例详解6-- Struts的模块使用实例
- Python中线程编程之threading模块的使用详解
- Express中method-override模块详解(一): 使用
- NDK使用静态库模块组织代码详解
- Python标准库之Sys模块使用详解
- Burp Suite详细使用教程-Intruder模块详解
- Burp Suite详细使用教程-Intruder模块详解
- apache使用日志分割模块rotatelogs分割日志详解
- Burp Suite详细使用教程-Intruder模块详解
- NDK使用静态库模块组织代码详解
- Burp Suite详细使用教程-Intruder模块详解
- Python中使用logging模块打印log日志详解
- 使用OpenCV的GPU模块(Win7x64+VS2010+OpenCV2.4.5+CUDA5.0)配置详解
- Burp Suite详细使用教程-Intruder模块详解
- Python 的MySQLConnector模块使用方法详解