May 2017
Intermediate to advanced
280 pages
6h 2m
English
Deque rotation allows rotation of items on either side. For right-side rotation, the notation is (+n) and for left-side rotation, the notation used is (-n), where n is the number of rotations:
import collectionsd = collections.deque(xrange(6))print "Normal queue", dd.rotate(2)print "nRight rotation :", dd1 = collections.deque(xrange(6))d1.rotate(-2)print "nleft rotation :", d1
In this case, using the xrange() function we generate a list of 5 numbers, which will serve as input to our deque. We rotate the deque on the right side and then on the left side. The results can be seen here:

From the output, we can observe that in ...
Read now
Unlock full access