|
|
@ -320,12 +320,14 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span> |
|
|
|
(<span class="hljs-string">'x'</span>, <span class="hljs-string">'y'</span>) |
|
|
|
</code></pre> |
|
|
|
<h2 id="iterator"><a href="#iterator" name="iterator">#</a>Iterator</h2> |
|
|
|
<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 |
|
|
|
</code></pre> |
|
|
|
<pre><code class="python language-python hljs"><iter> = iter(<collection>) |
|
|
|
<p><strong>Iterator is any object with next() special method.</strong></p> |
|
|
|
<pre><code class="python language-python hljs"><iter> = iter(<collection>) <span class="hljs-comment"># Calling `iter(<iter>)` returns the same object.</span> |
|
|
|
<iter> = iter(<function>, to_exclusive) <span class="hljs-comment"># Sequence of return values until 'to_exclusive'.</span> |
|
|
|
<el> = next(<iter> [, default]) <span class="hljs-comment"># Raises StopIteration or returns 'default' on end.</span> |
|
|
|
</code></pre> |
|
|
|
<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 |
|
|
|
</code></pre> |
|
|
|
<pre><code class="python language-python hljs"><iter> = count(start=<span class="hljs-number">0</span>, step=<span class="hljs-number">1</span>) <span class="hljs-comment"># Returns incremented value endlessly.</span> |
|
|
|
<iter> = repeat(<el> [, times]) <span class="hljs-comment"># Returns element endlessly or 'times' times.</span> |
|
|
|
<iter> = cycle(<collection>) <span class="hljs-comment"># Repeats the sequence indefinitely.</span> |
|
|
|