From ab8591bf2d2f71bbf8cf596f068ff5c65f4f18b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= <sornjure@gmail.com> Date: Fri, 21 Jun 2019 06:59:03 +0200 Subject: [PATCH] Iterator --- README.md | 10 ++++++---- index.html | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 64b14ae..647ee99 100644 --- a/README.md +++ b/README.md @@ -178,14 +178,16 @@ Point(x=1, y=2) Iterator -------- +**Iterator is any object with next() special method.** ```python -from itertools import count, repeat, cycle, chain, islice +<iter> = iter(<collection>) # Calling `iter(<iter>)` returns the same object. +<iter> = iter(<function>, to_exclusive) # Sequence of return values until 'to_exclusive'. +<el> = next(<iter> [, default]) # Raises StopIteration or returns 'default' on end. ``` +### Itertools ```python -<iter> = iter(<collection>) -<iter> = iter(<function>, to_exclusive) # Sequence of return values until 'to_exclusive'. -<el> = next(<iter> [, default]) # Raises StopIteration or returns 'default' on end. +from itertools import count, repeat, cycle, chain, islice ``` ```python diff --git a/index.html b/index.html index e639f46..fddf545 100644 --- a/index.html +++ b/index.html @@ -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>