~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Doc/library/heapq.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
   >>> data == ordered
87
87
   True
88
88
 
 
89
Using a heap to insert items at the correct place in a priority queue:
 
90
 
 
91
   >>> heap = []
 
92
   >>> data = [(1, 'J'), (4, 'N'), (3, 'H'), (2, 'O')]
 
93
   >>> for item in data:
 
94
   ...     heappush(heap, item)
 
95
   ...
 
96
   >>> while heap:
 
97
   ...     print(heappop(heap)[1])
 
98
   J
 
99
   O
 
100
   H
 
101
   N
 
102
 
 
103
 
89
104
The module also offers three general purpose functions based on heaps.
90
105
 
91
106