|
165 | 165 | <pre><code class="python language-python hljs"><dict>.update(<dict>) <span class="hljs-comment"># Adds items. Replaces ones with matching keys.</span>
|
166 | 166 | value = <dict>.pop(key) <span class="hljs-comment"># Removes item or raises KeyError if missing.</span>
|
167 | 167 | {k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> <dict>.items() <span class="hljs-keyword">if</span> v == value} <span class="hljs-comment"># Returns set of keys that point to the value.</span>
|
168 |
| -{k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> <dict>.items() <span class="hljs-keyword">if</span> k <span class="hljs-keyword">in</span> keys} <span class="hljs-comment"># Filters the dictionary by keys.</span> |
| 168 | +{k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> <dict>.items() <span class="hljs-keyword">if</span> k <span class="hljs-keyword">in</span> keys} <span class="hljs-comment"># Filters the dictionary by specified keys.</span> |
169 | 169 | </code></pre>
|
170 | 170 | <div><h3 id="counter">Counter</h3><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> Counter
|
171 | 171 | <span class="hljs-meta">>>> </span>counter = Counter([<span class="hljs-string">'blue'</span>, <span class="hljs-string">'blue'</span>, <span class="hljs-string">'blue'</span>, <span class="hljs-string">'red'</span>, <span class="hljs-string">'red'</span>])
|
|
335 | 335 | <bool> = <str>.isnumeric() <span class="hljs-comment"># Checks for [¼½¾…], [零〇一…] and isdigit().</span>
|
336 | 336 | <bool> = <str>.isalnum() <span class="hljs-comment"># Checks for [a-zA-Z…] and isnumeric().</span>
|
337 | 337 | <bool> = <str>.isprintable() <span class="hljs-comment"># Checks for [ !#$%…] and isalnum().</span>
|
338 |
| -<bool> = <str>.isspace() <span class="hljs-comment"># Checks for [ \t\n\r\f\v\x1c-\x1f\x85\xa0…].</span> |
| 338 | +<bool> = <str>.isspace() <span class="hljs-comment"># Checks for [ \t\n\r\f\v\x1c-\x1f\x85…].</span> |
339 | 339 | </code></pre></div>
|
340 | 340 |
|
341 | 341 | <div><h2 id="regex"><a href="#regex" name="regex">#</a>Regex</h2><p><strong>Functions for regular expression matching.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> re
|
|
502 | 502 | <div><h3 id="bitwiseoperators">Bitwise Operators</h3><pre><code class="python language-python hljs"><int> = <int> & <int> <span class="hljs-comment"># E.g. `0b1100 & 0b1010 == 0b1000`.</span>
|
503 | 503 | <int> = <int> | <int> <span class="hljs-comment"># E.g. `0b1100 | 0b1010 == 0b1110`.</span>
|
504 | 504 | <int> = <int> ^ <int> <span class="hljs-comment"># E.g. `0b1100 ^ 0b1010 == 0b0110`.</span>
|
505 |
| -<int> = <int> << n_bits <span class="hljs-comment"># E.g. `0b1100 << 4 == 0b1100_0000`.</span> |
| 505 | +<int> = <int> << n_bits <span class="hljs-comment"># E.g. `0b1111 << 4 == 0b11110000`.</span> |
506 | 506 | <int> = ~<int> <span class="hljs-comment"># E.g. `~0b1 == -0b10 == -(0b1+1)`.</span>
|
507 | 507 | </code></pre></div>
|
508 | 508 |
|
|
0 commit comments