Browse Source

List

pull/192/head
Jure Šorn 5 months ago
parent
commit
8292bc981e
3 changed files with 12 additions and 9 deletions
  1. 7
      README.md
  2. 11
      index.html
  3. 3
      pdf/remove_links.py

7
README.md

@ -50,7 +50,7 @@ List
```
```python
<el> = max(<collection>) # Returns largest element. Also max(<el_1>, ...).
<el> = max(<collection>) # Returns largest element. Also min(<el_1>, ...).
<num> = sum(<collection>) # Returns sum of elements. Also math.prod(<coll>).
```
@ -61,10 +61,11 @@ sorted_by_both = sorted(<collection>, key=lambda el: (el[1], el[0]))
flatter_list = list(itertools.chain.from_iterable(<list>))
```
* **For details about sort(), sorted(), min() and max() see [sortable](#sortable).**
* **Module [operator](#operator) provides functions itemgetter() and mul() that offer the same functionality as [lambda](#lambda) expressions above.**
* **Module [operator](#operator) has function itemgetter() that can replace listed [lambdas](#lambda).**
* **This text uses the term 'collection' instead of 'iterable'. For rationale see [collection](#collection).**
```python
<int> = len(<list>) # Returns number of items. Also works on other collections.
<int> = len(<list>) # Returns number of items. Also works on dict, set and string.
<int> = <list>.count(<el>) # Returns number of occurrences. Also `if <el> in <coll>: ...`.
<int> = <list>.index(<el>) # Returns index of the first occurrence or raises ValueError.
<el> = <list>.pop() # Removes and returns item from the end or at index if passed.

11
index.html

@ -55,7 +55,7 @@
<body>
<header>
<aside>November 14, 2024</aside>
<aside>November 17, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -114,7 +114,7 @@
&lt;list&gt; = sorted(&lt;collection&gt;) <span class="hljs-comment"># Returns new list with sorted elements.</span>
&lt;iter&gt; = reversed(&lt;list&gt;) <span class="hljs-comment"># Returns reversed iterator of elements.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;el&gt; = max(&lt;collection&gt;) <span class="hljs-comment"># Returns largest element. Also max(&lt;el_1&gt;, ...).</span>
<pre><code class="python language-python hljs">&lt;el&gt; = max(&lt;collection&gt;) <span class="hljs-comment"># Returns largest element. Also min(&lt;el_1&gt;, ...).</span>
&lt;num&gt; = sum(&lt;collection&gt;) <span class="hljs-comment"># Returns sum of elements. Also math.prod(&lt;coll&gt;).</span>
</code></pre>
<pre><code class="python language-python hljs">elementwise_sum = [sum(pair) <span class="hljs-keyword">for</span> pair <span class="hljs-keyword">in</span> zip(list_a, list_b)]
@ -124,9 +124,10 @@ flatter_list = list(itertools.chain.from_iterable(&lt;list&gt;))
</code></pre>
<ul>
<li><strong>For details about sort(), sorted(), min() and max() see <a href="#sortable">sortable</a>.</strong></li>
<li><strong>Module <a href="#operator">operator</a> provides functions itemgetter() and mul() that offer the same functionality as <a href="#lambda">lambda</a> expressions above.</strong></li>
<li><strong>Module <a href="#operator">operator</a> has function itemgetter() that can replace listed <a href="#lambda">lambdas</a>.</strong></li>
<li><strong>This text uses the term 'collection' instead of 'iterable'. For rationale see <a href="#collection">collection</a>.</strong></li>
</ul>
<pre><code class="python language-python hljs">&lt;int&gt; = len(&lt;list&gt;) <span class="hljs-comment"># Returns number of items. Also works on other collections.</span>
<pre><code class="python language-python hljs">&lt;int&gt; = len(&lt;list&gt;) <span class="hljs-comment"># Returns number of items. Also works on dict, set and string.</span>
&lt;int&gt; = &lt;list&gt;.count(&lt;el&gt;) <span class="hljs-comment"># Returns number of occurrences. Also `if &lt;el&gt; in &lt;coll&gt;: ...`.</span>
&lt;int&gt; = &lt;list&gt;.index(&lt;el&gt;) <span class="hljs-comment"># Returns index of the first occurrence or raises ValueError.</span>
&lt;el&gt; = &lt;list&gt;.pop() <span class="hljs-comment"># Removes and returns item from the end or at index if passed.</span>
@ -2923,7 +2924,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active
<footer>
<aside>November 14, 2024</aside>
<aside>November 17, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

3
pdf/remove_links.py

@ -8,7 +8,8 @@ from pathlib import Path
MATCHES = {
'<strong>For details about sort(), sorted(), min() and max() see <a href="#sortable">sortable</a>.</strong>': '<strong>For details about sort(), sorted(), min() and max() see sortable (p. 16).</strong>',
'<strong>Module <a href="#operator">operator</a> provides functions itemgetter() and mul() that offer the same functionality as <a href="#lambda">lambda</a> expressions above.</strong>': '<strong>Module \'operator\' (p. 31) provides functions itemgetter() and mul() that offer the same functionality as lambda expressions (p. 11) above.</strong>',
'<strong>Module <a href="#operator">operator</a> has function itemgetter() that can replace listed <a href="#lambda">lambdas</a>.</strong>': '<strong>Module \'operator\' has function itemgetter() that can replace listed lambdas (p. 11, 31).</strong>',
'<strong>This text uses the term \'collection\' instead of \'iterable\'. For rationale see <a href="#collection">collection</a>.</strong>': '<strong>This text uses the term \'collection\' instead of \'iterable\'. For rationale see collection (p. 18).</strong>',
'<strong>Adding <code class="python hljs"><span class="hljs-string">\'!r\'</span></code> to the expression converts object to string by calling its <a href="#class">repr()</a> method.</strong>': '<strong>Adding <code class="python hljs"><span class="hljs-string">\'!r\'</span></code> to the expression converts object to string by calling its repr() method.</strong>',
'<strong>It can be any <a href="#callable">callable</a>, but is usually implemented as a function that returns a <a href="#closure">closure</a>.</strong>': '<strong>It can be any callable, but is usually implemented as a function that returns a closure.</strong>',
'<strong>Hints are used by type checkers like <a href="https://pypi.org/project/mypy/">mypy</a>, data validation libraries such as <a href="https://pypi.org/project/pydantic/">Pydantic</a> and lately also by <a href="https://pypi.org/project/Cython/">Cython</a> compiler. However, they are not enforced by CPython interpreter.</strong>': '<strong>Hints are used by type checkers like mypy, data validation libraries such as Pydantic and lately also by Cython compiler. However, they are not enforced by CPython interpreter.</strong>',

Loading…
Cancel
Save