From 32d1408192c80f072afdf92ca3ab0ef6622387e7 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 4 Dec 2008 18:59:16 +0000 Subject: [PATCH] Add another heapq example. --- Doc/library/heapq.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst index 5cf81635ab..2190b8057e 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. -- 2.50.1