有元组的Python deque extendeldleft?

2024-07-08 11:16:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个最大长度为10的deque。可以.extendleft并添加元组。例如:

from collections import deque

x = deque(maxlen = 10)
z = [(1,4),(1,3),(2,5),(7,1),(6,4),(8,2),(9,1),(9,5),(7,3),(8,3)] 
for y in z:
    x.append(y)
print x
x.extendleft((6,7))
print x

退货:

^{pr2}$

我试过了: 对=(6,7) x、 伸缩(对) 同样的结果。在


Tags: infromimportforcollections元组printappend
1条回答
网友
1楼 · 发布于 2024-07-08 11:16:00
In [7]: x.extendleft([(6,7)])

In [8]: x
Out[8]: deque([(6, 7), (1, 4), (1, 3), (2, 5), (7, 1), (6, 4), (8, 2), (9, 1), (9, 5), (7, 3)], maxlen=10)

或者更简单:

^{pr2}$

相关问题 更多 >

    热门问题