Deque

A Deque double-ended queue. It can be visualized similar to a hollow tube or pipe, which is open at the both ends. Deques allows addition and removal of elements from either ends. It will be more clear with examples:

import collections 

de = collections.deque('India')
print 'deque:', de
print 'Lenght :', len(de)
print 'left end:', de[0]
print 'right end:', de[-1]

de.remove('a')

print 'After removing:', de

Here we are providing input to deque 'India' and we are printing the left-hand side and right-hand side elements of deque using the index and then we are removing a character 'a' from the right-hand side of the deque using remove(). The output will look something like this:

The len() function gives the length of the deque.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.197.95