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

Skip to content

Commit 3b965de

Browse files
committed
Dict, Closure
1 parent 534555c commit 3b965de

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ value = <dict>.setdefault(key, default=None) # Returns and writes default if
8989

9090
```python
9191
<dict>.update(<dict>) # Adds items. Replaces ones with matching keys.
92-
value = <dict>.pop(key) # Removes item or raises KeyError.
92+
value = <dict>.pop(key) # Removes item or raises KeyError if missing.
9393
{k for k, v in <dict>.items() if v == value} # Returns set of keys that point to the value.
9494
{k: v for k, v in <dict>.items() if k in keys} # Returns a dictionary, filtered by keys.
9595
```
@@ -862,7 +862,7 @@ from functools import partial
862862
30
863863
```
864864
* **Partial is also useful in cases when function needs to be passed as an argument because it enables us to set its arguments beforehand.**
865-
* **A few examples being: `'defaultdict(<function>)'`, `'iter(<function>, to_exclusive)'` and dataclass's `'field(default_factory=<function>)'`.**
865+
* **A few examples being: `'defaultdict(<func>)'`, `'iter(<func>, to_exc)'` and dataclass's `'field(default_factory=<func>)'`.**
866866

867867
### Non-Local
868868
**If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.**

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
&lt;dict&gt; = dict.fromkeys(keys [, value]) <span class="hljs-comment"># Creates a dict from collection of keys.</span>
146146
</code></pre>
147147
<pre><code class="python language-python hljs">&lt;dict&gt;.update(&lt;dict&gt;) <span class="hljs-comment"># Adds items. Replaces ones with matching keys.</span>
148-
value = &lt;dict&gt;.pop(key) <span class="hljs-comment"># Removes item or raises KeyError.</span>
148+
value = &lt;dict&gt;.pop(key) <span class="hljs-comment"># Removes item or raises KeyError if missing.</span>
149149
{k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> &lt;dict&gt;.items() <span class="hljs-keyword">if</span> v == value} <span class="hljs-comment"># Returns set of keys that point to the value.</span>
150150
{k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> &lt;dict&gt;.items() <span class="hljs-keyword">if</span> k <span class="hljs-keyword">in</span> keys} <span class="hljs-comment"># Returns a dictionary, filtered by keys.</span>
151151
</code></pre>
@@ -729,7 +729,7 @@
729729
</code></pre>
730730
<ul>
731731
<li><strong>Partial is also useful in cases when function needs to be passed as an argument because it enables us to set its arguments beforehand.</strong></li>
732-
<li><strong>A few examples being: <code class="python hljs"><span class="hljs-string">'defaultdict(&lt;function&gt;)'</span></code>, <code class="python hljs"><span class="hljs-string">'iter(&lt;function&gt;, to_exclusive)'</span></code> and dataclass's <code class="python hljs"><span class="hljs-string">'field(default_factory=&lt;function&gt;)'</span></code>.</strong></li>
732+
<li><strong>A few examples being: <code class="python hljs"><span class="hljs-string">'defaultdict(&lt;func&gt;)'</span></code>, <code class="python hljs"><span class="hljs-string">'iter(&lt;func&gt;, to_exc)'</span></code> and dataclass's <code class="python hljs"><span class="hljs-string">'field(default_factory=&lt;func&gt;)'</span></code>.</strong></li>
733733
</ul>
734734
<div><h3 id="nonlocal">Non-Local</h3><p><strong>If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_counter</span><span class="hljs-params">()</span>:</span>
735735
i = <span class="hljs-number">0</span>

0 commit comments

Comments
 (0)