From: Georg Brandl Date: Thu, 4 Dec 2008 18:59:16 +0000 (+0000) Subject: Add another heapq example. X-Git-Tag: v2.7a1~2591 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32d1408192c80f072afdf92ca3ab0ef6622387e7;p=thirdparty%2FPython%2Fcpython.git Add another heapq example. --- diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst index 5cf81635abd2..2190b8057e05 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.