<pre><codeclass="python language-python hljs"><deque> = deque(<collection>) <spanclass="hljs-comment"># Also `maxlen=None`.</span>
<pre><codeclass="python language-python hljs"><deque> = deque(<collection>) <spanclass="hljs-comment"># Use `maxlen=<int>` to set size limit.</span>
<deque>.appendleft(<el>) <spanclass="hljs-comment"># Opposite element is dropped if full.</span>
<deque>.rotate(n=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Rotates elements to the right.</span>
<el> = <deque>.popleft() <spanclass="hljs-comment"># Raises IndexError if empty.</span>
<deque>.rotate(n=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Last element becomes first.</span>
<el> = <deque>.popleft() <spanclass="hljs-comment"># Raises IndexError if deque is empty.</span>
</code></pre>
<div><h2id="threading"><ahref="#threading"name="threading">#</a>Threading</h2><p><strong>CPython interpreter can only run a single thread at a time. Using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> threading <spanclass="hljs-keyword">import</span> Thread, Timer, RLock, Semaphore, Event, Barrier