From 96f2f7c5a4ff303a2a1466bc3e18a98818601e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 29 Jun 2019 19:53:18 +0200 Subject: [PATCH] Deque --- README.md | 12 +++++++++++- index.html | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ec5064..1999681 100644 --- a/README.md +++ b/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 .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 --------- diff --git a/index.html b/index.html index fd7e659..f82e628 100644 --- a/index.html +++ b/index.html @@ -1362,7 +1362,7 @@ db.commit() <memoryview>.release()

#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".

from collections import deque
 <deque> = deque(<collection>, maxlen=None)
 
@@ -1372,6 +1372,14 @@ db.commit()
<deque>.extendleft(<collection>)  # Collection gets reversed.
 <deque>.rotate(n=1)               # Rotates elements to the right.
 
+
>>> 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

from threading import Thread, RLock