Browse Source

Deque

pull/36/head
Jure Šorn 5 years ago
parent
commit
96f2f7c5a4
2 changed files with 20 additions and 2 deletions
  1. 12
      README.md
  2. 10
      index.html

12
README.md

@ -1572,7 +1572,7 @@ Memory View
Deque
-----
**Thread-safe list with efficient appends and pops from either side. Pronounced "deck".**
**A thread-safe list with efficient appends and pops from either side. Pronounced "deck".**
```python
from collections import deque
@ -1589,6 +1589,16 @@ from collections import deque
<deque>.rotate(n=1) # Rotates elements to the right.
```
```python
>>> a = deque([1, 2, 3], maxlen=3)
>>> a.append(4)
[2, 3, 4]
>>> a.appendleft(5)
[5, 2, 3]
>>> a.insert(6, 1)
IndexError: deque already at its maximum size
```
Threading
---------

10
index.html

@ -1362,7 +1362,7 @@ db.commit()
&lt;memoryview&gt;.release()
</code></pre>
<h2 id="deque"><a href="#deque" name="deque">#</a>Deque</h2>
<p><strong>Thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p>
<p><strong>A thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p>
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> deque
&lt;deque&gt; = deque(&lt;collection&gt;, maxlen=<span class="hljs-keyword">None</span>)
</code></pre>
@ -1372,6 +1372,14 @@ db.commit()
<pre><code class="python language-python hljs">&lt;deque&gt;.extendleft(&lt;collection&gt;) <span class="hljs-comment"># Collection gets reversed.</span>
&lt;deque&gt;.rotate(n=<span class="hljs-number">1</span>) <span class="hljs-comment"># Rotates elements to the right.</span>
</code></pre>
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>a = deque([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], maxlen=<span class="hljs-number">3</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>a.append(<span class="hljs-number">4</span>)
[<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>a.appendleft(<span class="hljs-number">5</span>)
[<span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>a.insert(<span class="hljs-number">6</span>, <span class="hljs-number">1</span>)
IndexError: deque already at its maximum size
</code></pre>
<h2 id="threading"><a href="#threading" name="threading">#</a>Threading</h2>
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> threading <span class="hljs-keyword">import</span> Thread, RLock
</code></pre>

Loading…
Cancel
Save