|
272 | 272 | </code></pre>
|
273 | 273 | <pre><code class="python language-python hljs">value = <dict>.pop(key) <span class="hljs-comment"># Removes item or raises KeyError.</span>
|
274 | 274 | <dict>.update(<dict>) <span class="hljs-comment"># Adds items. Replaces ones with matching keys.</span>
|
275 |
| -[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 list of keys that point to value.</span> |
| 275 | +[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 list of keys that point to the value.</span> |
276 | 276 | {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"># Returns dictionary filtered by keys.</span>
|
277 | 277 | </code></pre>
|
278 | 278 | <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
|
|
344 | 344 | <div><h2 id="iterator"><a href="#iterator" name="iterator">#</a>Iterator</h2><pre><code class="python language-python hljs"><iter> = iter(<collection>) <span class="hljs-comment"># `iter(<iter>)` returns unmodified iterator.</span>
|
345 | 345 | <iter> = iter(<function>, to_exclusive) <span class="hljs-comment"># A sequence of return values until 'to_exclusive'.</span>
|
346 | 346 | <el> = next(<iter> [, default]) <span class="hljs-comment"># Raises StopIteration or returns 'default' on end.</span>
|
| 347 | +<list> = list(<iter>) <span class="hljs-comment"># Returns a list of iterator's remaining elements.</span> |
347 | 348 | </code></pre></div>
|
348 | 349 |
|
349 | 350 | <div><h3 id="itertools">Itertools</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> itertools <span class="hljs-keyword">import</span> count, repeat, cycle, chain, islice
|
|
357 | 358 | <iter> = chain.from_iterable(<collection>) <span class="hljs-comment"># Empties collections inside a collection in order.</span>
|
358 | 359 | </code></pre>
|
359 | 360 | <pre><code class="python language-python hljs"><iter> = islice(<collection>, to_exclusive)
|
360 |
| -<iter> = islice(<collection>, from_inclusive, to_exclusive) |
361 |
| -<iter> = islice(<collection>, from_inclusive, to_exclusive, +step_size) |
| 361 | +<iter> = islice(<collection>, from_inclusive, to_exclusive [, +step_size]) |
362 | 362 | </code></pre>
|
363 | 363 | <div><h2 id="generator"><a href="#generator" name="generator">#</a>Generator</h2><ul>
|
364 | 364 | <li><strong>Any function that contains a yield statement returns a generator.</strong></li>
|
|
0 commit comments