summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-05-09 01:15:01 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-05-09 01:15:01 (GMT)
commite7169eb9ede900c9b311725ba50757177be223bf (patch)
treefe866c150606fa253fcffa179b286307f34616b8 /Lib
parent9d7c870c6d66c8b2e066001f31ac3037d50f7012 (diff)
downloadcpython-e7169eb9ede900c9b311725ba50757177be223bf.zip
cpython-e7169eb9ede900c9b311725ba50757177be223bf.tar.gz
cpython-e7169eb9ede900c9b311725ba50757177be223bf.tar.bz2
Add more examples.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_deque.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index a99de03..2afb179c 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -474,6 +474,57 @@ IndexError: pop from an empty deque
>>> d
deque(['c', 'b', 'a'])
+
+
+
+>>> def delete_nth(d, n):
+... "del d[n]"
+... d.rotate(-n)
+... d.popleft()
+... d.rotate(n)
+...
+>>> d = deque('abcdef')
+>>> delete_nth(d, 2) # remove the entry at d[2]
+>>> d
+deque(['a', 'b', 'd', 'e', 'f'])
+
+
+
+>>> def roundrobin(*iterables):
+... pending = deque(iter(i) for i in iterables)
+... while pending:
+... task = pending.popleft()
+... try:
+... yield task.next()
+... except StopIteration:
+... continue
+... pending.append(task)
+...
+
+>>> for value in roundrobin('abc', 'd', 'efgh'):
+... print value
+...
+a
+d
+e
+b
+f
+c
+g
+h
+
+
+>>> def maketree(iterable):
+... d = deque(iterable)
+... while len(d) > 1:
+... pair = [d.popleft(), d.popleft()]
+... d.append(pair)
+... return list(d)
+...
+>>> print maketree('abcdefgh')
+[[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
+
+
"""