Python – Dequeue

A double-ended queue, or deque, supports adding and removing elements from either end. The more commonly used stacks and queues are degenerate forms of deques, where the inputs and outputs are restricted to a single end.

import collections

DoubleEnded = collections.deque(["Mon","Tue","Wed"])


print ("Appended at right - ")
print (DoubleEnded)


print ("Appended at right at left is - ")
print (DoubleEnded)


print ("Deleting from right - ")
print (DoubleEnded)


print ("Deleting from left - ")
print (DoubleEnded)
Appended at right - 
deque(['Mon', 'Tue', 'Wed', 'Thu'])
Appended at right at left is - 
deque(['Sun', 'Mon', 'Tue', 'Wed', 'Thu'])
Deleting from right - 
deque(['Sun', 'Mon', 'Tue', 'Wed'])
Deleting from left - 
deque(['Mon', 'Tue', 'Wed'])