1. extend(iterable): - 此函数用于在双端队列的右端添加多个值。传递的参数是可迭代的。
2. extendleft(iterable): - 此函数用于在双端队列的左端添加多个值。传递的参数是可迭代的。由于左侧附加,订单被撤销。
3. reverse(): - 此函数用于反转 deque元素的顺序。
4. rotate(): - 此函数按参数中指定的数字旋转双端队列。如果指定的数字为负数,则向左旋转。其他轮换是正确的。
# Python code to demonstrate working of
# extend(), extendleft(), rotate(), reverse()
# importing "collections" for deque operations
import collections
# initializing deque
de = collections.deque([1, 2, 3,])
# using extend() to add numbers to right end
# adds 4,5,6 to right end
de.extend([4,5,6])
# printing modified deque
print ("The deque after extending deque at end is : ")
print (de)
# using extendleft() to add numbers to left end
# adds 7,8,9 to right end
de.extendleft([7,8,9])
# printing modified deque
print ("The deque after extending deque at beginning is : ")
print (de)
# using rotate() to rotate the deque
# rotates by 3 to left
de.rotate(-3)
# printing modified deque
print ("The deque after rotating deque is : ")
print (de)
# using reverse() to reverse the deque
de.reverse()
# printing modified deque
print ("The deque after reversing deque is : ")
print (de)








暂无数据