Browse Source

Map, copy, struct

pull/95/head
Jure Šorn 3 years ago
parent
commit
a56efa9662
2 changed files with 6 additions and 0 deletions
  1. 3
      README.md
  2. 3
      index.html

3
README.md

@ -773,6 +773,7 @@ for i in range(10):
### Map, Filter, Reduce
```python
from functools import reduce
<iter> = map(lambda x: x + 1, range(10)) # (1, 2, ..., 10)
<iter> = filter(lambda x: x > 5, range(10)) # (6, 7, 8, 9)
<obj> = reduce(lambda out, x: out + x, range(10)) # 45
@ -1061,6 +1062,7 @@ class MyClassWithSlots:
### Copy
```python
from copy import copy, deepcopy
<object> = copy(<object>)
<object> = deepcopy(<object>)
```
@ -1948,6 +1950,7 @@ Struct
```python
from struct import pack, unpack, iter_unpack
<bytes> = pack('<format>', <num_1> [, <num_2>, ...])
<tuple> = unpack('<format>', <bytes>)
<tuples> = iter_unpack('<format>', <bytes>)

3
index.html

@ -809,6 +809,7 @@ func(*args, **kwargs)
</code></pre></div>
<div><h3 id="mapfilterreduce">Map, Filter, Reduce</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> reduce
&lt;iter&gt; = map(<span class="hljs-keyword">lambda</span> x: x + <span class="hljs-number">1</span>, range(<span class="hljs-number">10</span>)) <span class="hljs-comment"># (1, 2, ..., 10)</span>
&lt;iter&gt; = filter(<span class="hljs-keyword">lambda</span> x: x &gt; <span class="hljs-number">5</span>, range(<span class="hljs-number">10</span>)) <span class="hljs-comment"># (6, 7, 8, 9)</span>
&lt;obj&gt; = reduce(<span class="hljs-keyword">lambda</span> out, x: out + x, range(<span class="hljs-number">10</span>)) <span class="hljs-comment"># 45</span>
@ -1039,6 +1040,7 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
<div><h3 id="copy">Copy</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> copy <span class="hljs-keyword">import</span> copy, deepcopy
&lt;object&gt; = copy(&lt;object&gt;)
&lt;object&gt; = deepcopy(&lt;object&gt;)
</code></pre></div>
@ -1754,6 +1756,7 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
<li><strong>Module that performs conversions between a sequence of numbers and a bytes object.</strong></li>
<li><strong>Machine’s native type sizes and byte order are used by default.</strong></li>
</ul><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> struct <span class="hljs-keyword">import</span> pack, unpack, iter_unpack
&lt;bytes&gt; = pack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;num_1&gt; [, &lt;num_2&gt;, ...])
&lt;tuple&gt; = unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)
&lt;tuples&gt; = iter_unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)

Loading…
Cancel
Save