Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a56efa9

Browse files
committed
Map, copy, struct
1 parent ca15335 commit a56efa9

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ for i in range(10):
773773
### Map, Filter, Reduce
774774
```python
775775
from functools import reduce
776+
776777
<iter> = map(lambda x: x + 1, range(10)) # (1, 2, ..., 10)
777778
<iter> = filter(lambda x: x > 5, range(10)) # (6, 7, 8, 9)
778779
<obj> = reduce(lambda out, x: out + x, range(10)) # 45
@@ -1061,6 +1062,7 @@ class MyClassWithSlots:
10611062
### Copy
10621063
```python
10631064
from copy import copy, deepcopy
1065+
10641066
<object> = copy(<object>)
10651067
<object> = deepcopy(<object>)
10661068
```
@@ -1948,6 +1950,7 @@ Struct
19481950

19491951
```python
19501952
from struct import pack, unpack, iter_unpack
1953+
19511954
<bytes> = pack('<format>', <num_1> [, <num_2>, ...])
19521955
<tuple> = unpack('<format>', <bytes>)
19531956
<tuples> = iter_unpack('<format>', <bytes>)

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@
809809
</code></pre></div>
810810

811811
<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
812+
812813
&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>
813814
&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>
814815
&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 @@
10391040

10401041

10411042
<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
1043+
10421044
&lt;object&gt; = copy(&lt;object&gt;)
10431045
&lt;object&gt; = deepcopy(&lt;object&gt;)
10441046
</code></pre></div>
@@ -1754,6 +1756,7 @@
17541756
<li><strong>Module that performs conversions between a sequence of numbers and a bytes object.</strong></li>
17551757
<li><strong>Machine’s native type sizes and byte order are used by default.</strong></li>
17561758
</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
1759+
17571760
&lt;bytes&gt; = pack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;num_1&gt; [, &lt;num_2&gt;, ...])
17581761
&lt;tuple&gt; = unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)
17591762
&lt;tuples&gt; = iter_unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)

0 commit comments

Comments
 (0)