Answer your question: since deque is a sequence , you can usually use str.join to form a string from the ordered elements of this collection. str.join works more broadly on any Python iterable to form a string of elements combined one after another.
BUT, assumption, instead of deque and rotate and join, you can also combine slices in the line itself to form a new line:
>>> z="string" >>> rot=3 >>> z[rot:]+z[:rot] 'ingstr'
What works in both directions:
>>> rz=z[rot:]+z[:rot] >>> rz 'ingstr' >>> rz[-rot:]+rz[:-rot] 'string'
Besides being easier to read (IMHO), it also turns out to be much faster:
from __future__ import print_function
Print
True f1: 0.32 secs f2: 5.02 secs faster is 1474.49% faster.
source share