Browse Source

Generator, lru_cache

pull/42/head
Jure Šorn 5 years ago
parent
commit
fd1846dfa9
3 changed files with 10 additions and 5 deletions
  1. 3
      README.md
  2. 5
      index.html
  3. 7
      parse.js

3
README.md

@ -217,8 +217,7 @@ from itertools import count, repeat, cycle, chain, islice
Generator
---------
* **Convenient way to implement the iterator protocol.**
* **Any function that contains a yield statement returns a generator object.**
* **Any function that contains a yield statement returns a generator.**
* **Generators and iterators are interchangeable.**
```python

5
index.html

@ -357,8 +357,7 @@ to_exclusive = <range>.stop
<iter> = islice(<collection>, from_inclusive, to_exclusive, +step_size)
</code></pre>
<div><h2 id="generator"><a href="#generator" name="generator">#</a>Generator</h2><ul>
<li><strong>Convenient way to implement the iterator protocol.</strong></li>
<li><strong>Any function that contains a yield statement returns a generator object.</strong></li>
<li><strong>Any function that contains a yield statement returns a generator.</strong></li>
<li><strong>Generators and iterators are interchangeable.</strong></li>
</ul><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">count</span><span class="hljs-params">(start, step)</span>:</span>
<span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>:
@ -879,7 +878,7 @@ creature = Creature(Point(<span class="hljs-number">0</span>, <span class="hljs
<span class="hljs-meta">@lru_cache(maxsize=None)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">fib</span><span class="hljs-params">(n)</span>:</span>
<span class="hljs-keyword">return</span> n <span class="hljs-keyword">if</span> n &lt; <span class="hljs-number">2</span> <span class="hljs-keyword">else</span> fib(n<span class="hljs-number">-2</span>) + fib(n<span class="hljs-number">-1</span>)
<span class="hljs-keyword">return</span> n <span class="hljs-keyword">if</span> n &lt; <span class="hljs-number">2</span> <span class="hljs-keyword">else</span> fib(n-<span class="hljs-number">2</span>) + fib(n-<span class="hljs-number">1</span>)
</code></pre></div>

7
parse.js

@ -208,6 +208,12 @@ const EVAL =
'<span class="hljs-meta">&gt;&gt;&gt; </span>literal_eval(<span class="hljs-string">\'abs(1)\'</span>)\n' +
'ValueError: malformed node or string\n';
const LRU_CACHE =
'<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> lru_cache\n' +
'\n' +
'<span class="hljs-meta">@lru_cache(maxsize=None)</span>\n' +
'<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">fib</span><span class="hljs-params">(n)</span>:</span>\n' +
' <span class="hljs-keyword">return</span> n <span class="hljs-keyword">if</span> n &lt; <span class="hljs-number">2</span> <span class="hljs-keyword">else</span> fib(n-<span class="hljs-number">2</span>) + fib(n-<span class="hljs-number">1</span>)\n';
function main() {
const html = getMd();
@ -307,6 +313,7 @@ function fixClasses() {
function fixHighlights() {
$(`code:contains(os.rename)`).html(OS_RENAME);
$(`code:contains(ValueError: malformed node)`).html(EVAL);
$(`code:contains(@lru_cache(maxsize=None))`).html(LRU_CACHE);
}
function preventPageBreaks() {

Loading…
Cancel
Save