]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add another heapq example.
authorGeorg Brandl <georg@python.org>
Thu, 4 Dec 2008 18:59:16 +0000 (18:59 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 4 Dec 2008 18:59:16 +0000 (18:59 +0000)
Doc/library/heapq.rst

index 5cf81635abd21cea89cb9ca00e4b260ad9924e7c..2190b8057e05826365250276c777d671e26d8338 100644 (file)
@@ -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.