<bytes> = pack('<format>', <el_1> [, ...]) # Packs objects according to format string.
<tuple> = unpack('<format>', <bytes>) # Use iter_unpack() to get iterator of tuples.
```
@ -2054,23 +2055,19 @@ from array import array
Memory View
-----------
* **A sequence object that points to the memory of another bytes-like object.**
* **Each element can reference a single or multiple consecutive bytes, depending on format.**
* **Order and number of elements can be changed with slicing.**
* **Casting only works between char and other types and uses system's sizes.**
* **Byte order is always determined by the system.**
**A sequence object that points to the memory of another bytes-like object. Each element can reference a single or multiple consecutive bytes, depending on format. Order and number of elements can be changed with slicing.**
```python
<mview> = memoryview(<bytes/bytearray/array>) # Immutable if bytes, else mutable.
<real> = <mview>[index] # Returns an int or a float.
<mview> = <mview>[<slice>] # Mview with rearranged elements.
<mview> = <mview>.cast('<typecode>') # Casts memoryview to the new format.
<mview>.release() # Releases memory buffer of target object.
<mview> = <mview>[<slice>] # Returns mview with rearranged elements.
<mview> = <mview>.cast('<typecode>') # Only works between b/B/c and other types.
<mview>.release() # Releases memory buffer of the base object.
```
```python
<bytes> = bytes(<mview>) # Returns a new bytes object.
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes object as sep.
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes as a separator.
<array> = array('<typecode>', <mview>) # Treats mview as a sequence of numbers.
<file>.write(<mview>) # Writes mview to the binary file.
```
@ -2088,11 +2085,14 @@ Deque
```python
from collections import deque
```
```python
<deque> = deque(<collection>) # Also `maxlen=None`.
<deque>.appendleft(<el>) # Opposite element is dropped if full.
<bytes> = pack(<spanclass="hljs-string">'<format>'</span>, <el_1> [, ...]) <spanclass="hljs-comment"># Packs objects according to format string.</span>
<tuple> = unpack(<spanclass="hljs-string">'<format>'</span>, <bytes>) <spanclass="hljs-comment"># Use iter_unpack() to get iterator of tuples.</span>
<div><h2id="memoryview"><ahref="#memoryview"name="memoryview">#</a>Memory View</h2><p><strong>A sequence object that points to the memory of another bytes-like object. Each element can reference a single or multiple consecutive bytes, depending on format. Order and number of elements can be changed with slicing.</strong></p><pre><codeclass="python language-python hljs"><mview> = memoryview(<bytes/bytearray/array>) <spanclass="hljs-comment"># Immutable if bytes, else mutable.</span>
<real> = <mview>[index] <spanclass="hljs-comment"># Returns an int or a float.</span>
<mview> = <mview>[<slice>] <spanclass="hljs-comment"># Mview with rearranged elements.</span>
<mview> = <mview>.cast(<spanclass="hljs-string">'<typecode>'</span>) <spanclass="hljs-comment"># Casts memoryview to the new format.</span>
<mview>.release() <spanclass="hljs-comment"># Releases memory buffer of target object.</span>
<mview> = <mview>[<slice>] <spanclass="hljs-comment"># Returns mview with rearranged elements.</span>
<mview> = <mview>.cast(<spanclass="hljs-string">'<typecode>'</span>) <spanclass="hljs-comment"># Only works between b/B/c and other types.</span>
<mview>.release() <spanclass="hljs-comment"># Releases memory buffer of the base object.</span>
</code></pre></div>
<pre><codeclass="python language-python hljs"><bytes> = bytes(<mview>) <spanclass="hljs-comment"># Returns a new bytes object.</span>
<bytes> = <bytes>.join(<coll_of_mviews>) <spanclass="hljs-comment"># Joins mviews using bytes object as sep.</span>
<bytes> = <bytes>.join(<coll_of_mviews>) <spanclass="hljs-comment"># Joins mviews using bytes as a separator.</span>
<array> = array(<spanclass="hljs-string">'<typecode>'</span>, <mview>) <spanclass="hljs-comment"># Treats mview as a sequence of numbers.</span>
<file>.write(<mview>) <spanclass="hljs-comment"># Writes mview to the binary file.</span>
<div><h2id="deque"><ahref="#deque"name="deque">#</a>Deque</h2><p><strong>A thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> collections <spanclass="hljs-keyword">import</span> deque
<deque> = deque(<collection>) <spanclass="hljs-comment"># Also `maxlen=None`.</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>
</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