How to remove deque element from start and from end in Python

1 Answer

0 votes
import collections     

d = collections.deque(range(10))   

print(d) 

d.popleft()
d.pop()
print(d) 

d.popleft()
d.pop()
print(d) 



'''
run:

deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
deque([1, 2, 3, 4, 5, 6, 7, 8])
deque([2, 3, 4, 5, 6, 7])

'''

 



answered May 7, 2019 by avibootz

Related questions

...