* **With 'total_ordering' decorator, you only need to provide eq() and one of lt(), gt(), le() or ge() special methods and the rest will be automatically generated.**
* **Functions sorted() and min() only require lt() method, while max() only requires gt(). However, it is best to define them all so that confusion doesn't arise in other contexts.**
* **When two lists, strings or dataclasses are compared, their values get compared in order until a pair of unequal values is found. The comparison of this two values is then returned. The shorter sequence is considered smaller in case of all values being equal.**
* **Characters are compared by their Unicode IDs. Use module 'locale' for proper alphabetical order.**
* **For proper alphabetical order pass `'key=locale.strxfrm'` to sorted() after running `'locale.setlocale(locale.LC_COLLATE, "en_US.UTF-8")'`.**
```python
from functools import total_ordering
@ -1842,7 +1842,7 @@ import csv
* **`'skipinitialspace'` - Is space character at the start of the field stripped by the reader.**
* **`'lineterminator'` - How writer terminates rows. Reader is hardcoded to '\n', '\r', '\r\n'.**
* **`'quoting'` - 0: As necessary, 1: All, 2: All but numbers which are read as floats, 3: None.**
* **`'escapechar'` - Character for escaping quotechars if doublequote is False.**
* **`'escapechar'` - Character for escaping quotechars if 'doublequote' is False.**
### Dialects
```text
@ -2080,10 +2080,7 @@ Deque
```python
from collections import deque
<deque> = deque(<collection>, maxlen=None)
```
```python
<deque> = deque(<collection>) # Also `maxlen=None`.
<deque>.appendleft(<el>) # Opposite element is dropped if full.
* **Bitwise operators require objects to have and(), or(), xor() and invert() special methods, unlike logical operators that work on all types of objects.**
* **Bitwise operators require objects to have and(), or() and xor() special methods, unlike logical operators that work on all types of objects.**
@ -961,7 +961,7 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
<li><strong>With 'total_ordering' decorator, you only need to provide eq() and one of lt(), gt(), le() or ge() special methods and the rest will be automatically generated.</strong></li>
<li><strong>Functions sorted() and min() only require lt() method, while max() only requires gt(). However, it is best to define them all so that confusion doesn't arise in other contexts.</strong></li>
<li><strong>When two lists, strings or dataclasses are compared, their values get compared in order until a pair of unequal values is found. The comparison of this two values is then returned. The shorter sequence is considered smaller in case of all values being equal.</strong></li>
<li><strong>Characters are compared by their Unicode IDs. Use module 'locale' for proper alphabetical order.</strong></li>
<li><strong>For proper alphabetical order pass <codeclass="python hljs"><spanclass="hljs-string">'key=locale.strxfrm'</span></code> to sorted() after running <codeclass="python hljs"><spanclass="hljs-string">'locale.setlocale(locale.LC_COLLATE, "en_US.UTF-8")'</span></code>.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'skipinitialspace'</span></code> - Is space character at the start of the field stripped by the reader.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'lineterminator'</span></code> - How writer terminates rows. Reader is hardcoded to '\n', '\r', '\r\n'.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'quoting'</span></code> - 0: As necessary, 1: All, 2: All but numbers which are read as floats, 3: None.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'escapechar'</span></code> - Character for escaping quotechars if doublequote is False.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'escapechar'</span></code> - Character for escaping quotechars if 'doublequote' is False.</strong></li>
</ul><div><h4id="besidesnumberspackandunpackalsosupportbytesobjectsaspartofthesequence">Besides numbers, pack() and unpack() also support bytes objects as part of the sequence:</h4><ul>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'c'</span></code> - A bytes object with a single element. For pad byte use <codeclass="python hljs"><spanclass="hljs-string">'x'</span></code>.</strong></li>
<li><strong><codeclass="apache hljs"><spanclass="hljs-section">'<n>s'</span><spanclass="hljs-attribute"></span></code> - A bytes object with n elements.</strong></li>
</ul><div><h4id="integertypesuseacapitalletterforunsignedtypeminimumandstandardsizesareinbrackets">Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:</h4><ul>
</ul></div></div><div><div><h4id="integertypesuseacapitalletterforunsignedtypeminimumandstandardsizesareinbrackets">Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:</h4><ul>
<spanclass="hljs-string">'<hex>'</span> = <mview>.hex() <spanclass="hljs-comment"># Treats mview as a bytes object.</span>
</code></pre>
<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
<pre><codeclass="python language-python hljs"><deque>.appendleft(<el>) <spanclass="hljs-comment"># Opposite element is dropped if full.</span>
<deque> = deque(<collection>) <spanclass="hljs-comment"># Also `maxlen=None`.</span>
<deque>.appendleft(<el>) <spanclass="hljs-comment"># Opposite element is dropped if full.</span>
<li><strong>CPython interpreter can only run a single thread at a time.</strong></li>
<li><strong>That is why using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.</strong></li>
<li><strong>Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. Its exception() method returns exception or None.</strong></li>
<li><strong>ProcessPoolExecutor provides true parallelism, but everything sent to/from workers must be <ahref="#pickle">pickable</a>. Queues must be sent using executor's 'initargs' and 'initializer' parameters.</strong></li>
</ul>
<div><h2id="operator"><ahref="#operator"name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> operator <spanclass="hljs-keyword">as</span> op
<div><h2id="operator"><ahref="#operator"name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> operator <spanclass="hljs-keyword">as</span> op
<bool> = op.not_(<obj>) <spanclass="hljs-comment"># not (or/and are not provided)</span>
<li><strong>Bitwise operators require objects to have and(), or(), xor() and invert() special methods, unlike logical operators that work on all types of objects.</strong></li>
<li><strong>Bitwise operators require objects to have and(), or() and xor() special methods, unlike logical operators that work on all types of objects.</strong></li>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><p><strong>Inspecting code at runtime.</strong></p><div><h3id="variables">Variables</h3><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Names of local variables (incl. functions).</span>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Names of local variables (incl. functions).</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local variables. Also locals().</span>
<dict> = globals() <spanclass="hljs-comment"># Dict of global variables.</span>