summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-12-04 18:59:16 (GMT)
committerGeorg Brandl <georg@python.org>2008-12-04 18:59:16 (GMT)
commit32d1408192c80f072afdf92ca3ab0ef6622387e7 (patch)
treed0bd810568aef75de88b503d2de01b9c9a3afcc3 /Doc
parent34196c851a92cfcde12532673f5d073e5ee6d6a3 (diff)
downloadcpython-32d1408192c80f072afdf92ca3ab0ef6622387e7.zip
cpython-32d1408192c80f072afdf92ca3ab0ef6622387e7.tar.gz
cpython-32d1408192c80f072afdf92ca3ab0ef6622387e7.tar.bz2
Add another heapq example.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/heapq.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index 5cf8163..2190b80 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -88,6 +88,21 @@ Example of use:
>>> print data == ordered
True
+Using a heap to insert items at the correct place in a priority queue:
+
+ >>> heap = []
+ >>> data = [(1, 'J'), (4, 'N'), (3, 'H'), (2, 'O')]
+ >>> for item in data:
+ ... heappush(heap, item)
+ ...
+ >>> while heap:
+ ... print heappop(heap)[1]
+ J
+ O
+ H
+ N
+
+
The module also offers three general purpose functions based on heaps.