|
56 | 56 |
|
57 | 57 | <body> |
58 | 58 | <header> |
59 | | - <aside>July 19, 2025</aside> |
| 59 | + <aside>July 20, 2025</aside> |
60 | 60 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
61 | 61 | </header> |
62 | 62 |
|
|
120 | 120 | <pre><code class="python language-python hljs"><list>.append(<el>) <span class="hljs-comment"># Appends element to the end. Also <list> += [<el>].</span> |
121 | 121 | <list>.extend(<collection>) <span class="hljs-comment"># Appends elements to the end. Also <list> += <coll>.</span> |
122 | 122 | </code></pre> |
123 | | -<pre><code class="python language-python hljs"><list>.sort() <span class="hljs-comment"># Sorts elements in ascending order.</span> |
124 | | -<list>.reverse() <span class="hljs-comment"># Reverses the list in-place.</span> |
125 | | -<list> = sorted(<collection>) <span class="hljs-comment"># Returns new list with sorted elements.</span> |
| 123 | +<pre><code class="python language-python hljs"><list>.sort() <span class="hljs-comment"># Sorts the elements in ascending order.</span> |
| 124 | +<list>.reverse() <span class="hljs-comment"># Reverses the order of list's elements.</span> |
| 125 | +<list> = sorted(<collection>) <span class="hljs-comment"># Returns a new list with sorted elements.</span> |
126 | 126 | <iter> = reversed(<list>) <span class="hljs-comment"># Returns reversed iterator of elements.</span> |
127 | 127 | </code></pre> |
128 | 128 | <pre><code class="python language-python hljs"><el> = max(<collection>) <span class="hljs-comment"># Returns largest element. Also min(<el_1>, ...).</span> |
|
153 | 153 | <view> = <dict>.values() <span class="hljs-comment"># Collection of values that reflects changes.</span> |
154 | 154 | <view> = <dict>.items() <span class="hljs-comment"># Coll. of key-value tuples that reflects chgs.</span> |
155 | 155 | </code></pre> |
156 | | -<pre><code class="python language-python hljs">value = <dict>.get(key, default=<span class="hljs-keyword">None</span>) <span class="hljs-comment"># Returns default if key is missing.</span> |
| 156 | +<pre><code class="python language-python hljs">value = <dict>.get(key, default=<span class="hljs-keyword">None</span>) <span class="hljs-comment"># Returns default argument if key is missing.</span> |
157 | 157 | value = <dict>.setdefault(key, default=<span class="hljs-keyword">None</span>) <span class="hljs-comment"># Returns and writes default if key is missing.</span> |
158 | 158 | <dict> = collections.defaultdict(<type>) <span class="hljs-comment"># Returns a dict with default value `<type>()`.</span> |
159 | 159 | <dict> = collections.defaultdict(<span class="hljs-keyword">lambda</span>: <span class="hljs-number">1</span>) <span class="hljs-comment"># Returns a dict with default value 1.</span> |
|
209 | 209 | <span class="hljs-meta">>>> </span>p = Point(<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>) |
210 | 210 | <span class="hljs-meta">>>> </span>print(p) |
211 | 211 | Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>) |
212 | | -<span class="hljs-meta">>>> </span>p[<span class="hljs-number">0</span>], p.y |
| 212 | +<span class="hljs-meta">>>> </span>p.x, p[<span class="hljs-number">1</span>] |
213 | 213 | (<span class="hljs-number">1</span>, <span class="hljs-number">2</span>) |
214 | 214 | </code></pre></div> |
215 | 215 |
|
|
239 | 239 |
|
240 | 240 | <pre><code class="python language-python hljs"><iter> = it.count(start=<span class="hljs-number">0</span>, step=<span class="hljs-number">1</span>) <span class="hljs-comment"># Returns updated value endlessly. Accepts floats.</span> |
241 | 241 | <iter> = it.repeat(<el> [, times]) <span class="hljs-comment"># Returns element endlessly or 'times' times.</span> |
242 | | -<iter> = it.cycle(<collection>) <span class="hljs-comment"># Repeats the sequence endlessly.</span> |
| 242 | +<iter> = it.cycle(<collection>) <span class="hljs-comment"># Repeats the passed sequence of elements endlessly.</span> |
243 | 243 | </code></pre> |
244 | | -<pre><code class="python language-python hljs"><iter> = it.chain(<coll>, <coll> [, ...]) <span class="hljs-comment"># Empties collections in order (figuratively).</span> |
| 244 | +<pre><code class="python language-python hljs"><iter> = it.chain(<coll>, <coll> [, ...]) <span class="hljs-comment"># Empties collections in order (only figuratively).</span> |
245 | 245 | <iter> = it.chain.from_iterable(<coll>) <span class="hljs-comment"># Empties collections inside a collection in order.</span> |
246 | 246 | </code></pre> |
247 | 247 | <pre><code class="python language-python hljs"><iter> = it.islice(<coll>, to_exclusive) <span class="hljs-comment"># Only returns first 'to_exclusive' elements.</span> |
@@ -2938,7 +2938,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2938 | 2938 |
|
2939 | 2939 |
|
2940 | 2940 | <footer> |
2941 | | - <aside>July 19, 2025</aside> |
| 2941 | + <aside>July 20, 2025</aside> |
2942 | 2942 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2943 | 2943 | </footer> |
2944 | 2944 |
|
|
0 commit comments