Kaydet (Commit) 32d14081 authored tarafından Georg Brandl's avatar Georg Brandl

Add another heapq example.

üst 34196c85
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment