Browse Source

Dictionary

pull/46/head
Jure Šorn 4 years ago
parent
commit
339eb47a02
2 changed files with 5 additions and 5 deletions
  1. 4
      README.md
  2. 6
      index.html

4
README.md

@ -86,9 +86,9 @@ value = <dict>.setdefault(key, default=None) # Returns and writes default if
```
```python
value = <dict>.pop(key) # Removes item or raises KeyError.
<dict>.update(<dict>) # Adds items. Replaces ones with matching keys.
[k for k, v in <dict>.items() if v == value] # Returns list of keys that point to the value.
value = <dict>.pop(key) # Removes item or raises KeyError.
{k for k, v in <dict>.items() if v == value} # Returns set of keys that point to the value.
{k: v for k, v in <dict>.items() if k in keys} # Returns dictionary filtered by keys.
```

6
index.html

@ -270,9 +270,9 @@ value = &lt;dict&gt;.setdefault(key, default=<span class="hljs-keyword">None</s
&lt;dict&gt; = dict(zip(keys, values)) <span class="hljs-comment"># Creates a dict from two collections.</span>
&lt;dict&gt; = dict.fromkeys(keys [, value]) <span class="hljs-comment"># Creates a dict from collection of keys.</span>
</code></pre>
<pre><code class="python language-python hljs">value = &lt;dict&gt;.pop(key) <span class="hljs-comment"># Removes item or raises KeyError.</span>
&lt;dict&gt;.update(&lt;dict&gt;) <span class="hljs-comment"># Adds items. Replaces ones with matching keys.</span>
[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 list of keys that point to the value.</span>
<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>
value = &lt;dict&gt;.pop(key) <span class="hljs-comment"># Removes item or raises KeyError.</span>
{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>
{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 dictionary filtered by keys.</span>
</code></pre>
<div><h3 id="counter">Counter</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> Counter

Loading…
Cancel
Save