* **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.**
* **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.**
@ -1525,11 +1525,11 @@ arguments = sys.argv[1:]
```python
from argparse import ArgumentParser, FileType
p = ArgumentParser(description=<str>)
p.add_argument('-<short_name>', '--<name>', action='store_true') # Flag
@ -950,7 +950,7 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
<div><h3id="sortable">Sortable</h3><ul>
<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>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>Only required methods are iter() and len().</strong></li>
<li><strong>This cheatsheet actually means <codeclass="python hljs"><spanclass="hljs-string">'<iterable>'</span></code> when it uses <codeclass="python hljs"><spanclass="hljs-string">'<collection>'</span></code>.</strong></li>
<li><strong>I chose not to use the name 'iterable' because it sounds scarier and more vague than 'collection'. The only drawback of this decision is that a reader could think a certain function doesn't accept iterators when it does, since iterators are the only iterable objects that are not collections.</strong></li>
<li><strong>I chose not to use the name 'iterable' because it sounds scarier and more vague than 'collection'. The only drawback of this decision is that a reader could think a certain function doesn't accept iterators when it does, since iterators are the only built-in objects that are not collections while being iterable.</strong></li>
args = p.parse_args() <spanclass="hljs-comment"># Exits on error.</span>
value = args.<name>
</code></pre></div>
@ -1319,7 +1319,7 @@ value = args.<name>
<ul>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'encoding=None'</span></code> means that the default encoding is used, which is platform dependent. Best practice is to use <codeclass="python hljs"><spanclass="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on '\n', '\r' and '\r\n'.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'FileNotFoundError'</span></code> can be raised when reading with <codeclass="python hljs"><spanclass="hljs-string">'r'</span></code> or <codeclass="python hljs"><spanclass="hljs-string">'r+'</span></code>.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'FileExistsError'</span></code> can be raised when writing with <codeclass="python hljs"><spanclass="hljs-string">'x'</span></code>.</strong></li>
@ -2680,20 +2680,20 @@ b <span class="hljs-number">3</span> <span class="hljs-number">4</span>
<ul>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'<DF>[col_key_1, col_key_2][row_key]'</span></code> to get the fifth result's values.</strong></li>
<div><h3id="groupby">GroupBy</h3><p><strong>Object that groups together rows of a dataframe based on the value of the passed column.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>df = DataFrame([[<spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>, <spanclass="hljs-number">3</span>], [<spanclass="hljs-number">4</span>, <spanclass="hljs-number">5</span>, <spanclass="hljs-number">6</span>], [<spanclass="hljs-number">7</span>, <spanclass="hljs-number">8</span>, <spanclass="hljs-number">6</span>]], index=list(<spanclass="hljs-string">'abc'</span>), columns=list(<spanclass="hljs-string">'xyz'</span>))