Browse Source

Range

pull/135/head
Jure Šorn 2 years ago
parent
commit
406539f77b
2 changed files with 21 additions and 22 deletions
  1. 21
      README.md
  2. 22
      index.html

21
README.md

@ -144,9 +144,9 @@ Tuple
-----
**Tuple is an immutable and hashable list.**
```python
<tuple> = () # Empty tuple.
<tuple> = (<el>,) # Or: <el>,
<tuple> = (<el_1>, <el_2> [, ...]) # Or: <el_1>, <el_2> [, ...]
<tuple> = () # Empty tuple.
<tuple> = (<el>,) # Or: <el>,
<tuple> = (<el_1>, <el_2> [, ...]) # Or: <el_1>, <el_2> [, ...]
```
### Named Tuple
@ -168,17 +168,16 @@ Point(x=1, y=2)
Range
-----
**An immutable and hashable sequence of evenly spaced integers.**
**Immutable and hashable sequence of integers.**
```python
<range> = range(to_exclusive) # `list(range(3)) == [0, 1, 2]`
<range> = range(from_inclusive, to_exclusive) # `list(range(1, 4)) == [1, 2, 3]`
<range> = range(from_inclusive, to_exclusive, ±step) # `list(range(3, 0, -1)) == [3, 2, 1]`
<range> = range(stop) # range(to_exclusive)
<range> = range(start, stop) # range(from_inclusive, to_exclusive)
<range> = range(start, stop, ±step) # range(from_inclusive, to_exclusive, ±step_size)
```
```python
from_inclusive = <range>.start
to_exclusive = <range>.stop
>>> [i for i in range(3)]
[0, 1, 2]
```
@ -217,7 +216,7 @@ from itertools import count, repeat, cycle, chain, islice
```python
<iter> = islice(<coll>, to_exclusive) # Only returns first 'to_exclusive' elements.
<iter> = islice(<coll>, from_inclusive, …) # `to_exclusive, +step`.
<iter> = islice(<coll>, from_inclusive, …) # `to_exclusive, +step_size`.
```

22
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>July 13, 2022</aside>
<aside>July 18, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -182,9 +182,9 @@ Counter({<span class="hljs-string">'blue'</span>: <span class="hljs-number">3</s
</code></pre></div>
<div><h2 id="tuple"><a href="#tuple" name="tuple">#</a>Tuple</h2><p><strong>Tuple is an immutable and hashable list.</strong></p><pre><code class="python language-python hljs">&lt;tuple&gt; = () <span class="hljs-comment"># Empty tuple.</span>
&lt;tuple&gt; = (&lt;el&gt;,) <span class="hljs-comment"># Or: &lt;el&gt;,</span>
&lt;tuple&gt; = (&lt;el_1&gt;, &lt;el_2&gt; [, ...]) <span class="hljs-comment"># Or: &lt;el_1&gt;, &lt;el_2&gt; [, ...]</span>
<div><h2 id="tuple"><a href="#tuple" name="tuple">#</a>Tuple</h2><p><strong>Tuple is an immutable and hashable list.</strong></p><pre><code class="python language-python hljs">&lt;tuple&gt; = () <span class="hljs-comment"># Empty tuple.</span>
&lt;tuple&gt; = (&lt;el&gt;,) <span class="hljs-comment"># Or: &lt;el&gt;,</span>
&lt;tuple&gt; = (&lt;el_1&gt;, &lt;el_2&gt; [, ...]) <span class="hljs-comment"># Or: &lt;el_1&gt;, &lt;el_2&gt; [, ...]</span>
</code></pre></div>
@ -201,14 +201,14 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
</code></pre></div>
<div><h2 id="range"><a href="#range" name="range">#</a>Range</h2><p><strong>An immutable and hashable sequence of evenly spaced integers.</strong></p><pre><code class="python language-python hljs">&lt;range&gt; = range(to_exclusive) <span class="hljs-comment"># `list(range(3)) == [0, 1, 2]`</span>
&lt;range&gt; = range(from_inclusive, to_exclusive) <span class="hljs-comment"># `list(range(1, 4)) == [1, 2, 3]`</span>
&lt;range&gt; = range(from_inclusive, to_exclusive, ±step) <span class="hljs-comment"># `list(range(3, 0, -1)) == [3, 2, 1]`</span>
<div><h2 id="range"><a href="#range" name="range">#</a>Range</h2><p><strong>Immutable and hashable sequence of integers.</strong></p><pre><code class="python language-python hljs">&lt;range&gt; = range(stop) <span class="hljs-comment"># range(to_exclusive)</span>
&lt;range&gt; = range(start, stop) <span class="hljs-comment"># range(from_inclusive, to_exclusive)</span>
&lt;range&gt; = range(start, stop, ±step) <span class="hljs-comment"># range(from_inclusive, to_exclusive, ±step_size)</span>
</code></pre></div>
<pre><code class="python language-python hljs">from_inclusive = &lt;range&gt;.start
to_exclusive = &lt;range&gt;.stop
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>[i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">3</span>)]
[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]
</code></pre>
<div><h2 id="enumerate"><a href="#enumerate" name="enumerate">#</a>Enumerate</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">for</span> i, el <span class="hljs-keyword">in</span> enumerate(&lt;collection&gt; [, i_start]):
...
@ -231,7 +231,7 @@ to_exclusive = &lt;range&gt;.stop
&lt;iter&gt; = chain.from_iterable(&lt;coll&gt;) <span class="hljs-comment"># Empties collections inside a collection in order.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;iter&gt; = islice(&lt;coll&gt;, to_exclusive) <span class="hljs-comment"># Only returns first 'to_exclusive' elements.</span>
&lt;iter&gt; = islice(&lt;coll&gt;, from_inclusive, …) <span class="hljs-comment"># `to_exclusive, +step`.</span>
&lt;iter&gt; = islice(&lt;coll&gt;, from_inclusive, …) <span class="hljs-comment"># `to_exclusive, +step_size`.</span>
</code></pre>
<div><h2 id="generator"><a href="#generator" name="generator">#</a>Generator</h2><ul>
<li><strong>Any function that contains a yield statement returns a generator.</strong></li>
@ -2900,7 +2900,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>July 13, 2022</aside>
<aside>July 18, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

Loading…
Cancel
Save