Deque consumption

Deque can be consumed from either both ends or one end. For consuming deque elements or retrieval of elements, we use two functions: pop() and popleft(). It will be more clear with an example:

import collections
d1 = collections.deque("abcdefghacmqdcb")
print d1
print "Poped element ",d1.pop()
print d1
print "Poped left element ",d1.popleft()
print d1

Here we use pop to remove the elements one at a time from right end of the deque. In this case, char b is removed from the right end of the deque. The popleft() function removes element from the left end of the deque. Here, popleft() removed char a from the left end of the deque as shown:

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

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