mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
* Move collections.deque() in from the sandbox
* Add unittests, newsitem, and whatsnew * Apply to Queue.py mutex.py threading.py pydoc.py and shlex.py * Docs are forthcoming
This commit is contained in:
parent
141d4e5643
commit
756b3f3c15
15 changed files with 983 additions and 57 deletions
|
|
@ -80,22 +80,5 @@ breakpoints: 85 and up is an `A', 75..84 is a `B', etc.
|
|||
'C'
|
||||
>>> map(grade, [33, 99, 77, 44, 12, 88])
|
||||
['E', 'A', 'B', 'D', 'F', 'A']
|
||||
\end{verbatim}
|
||||
|
||||
The bisect module can be used with the Queue module to implement a priority
|
||||
queue (example courtesy of Fredrik Lundh): \index{Priority Queue}
|
||||
|
||||
\begin{verbatim}
|
||||
import Queue, bisect
|
||||
|
||||
class PriorityQueue(Queue.Queue):
|
||||
def _put(self, item):
|
||||
bisect.insort(self.queue, item)
|
||||
|
||||
# usage
|
||||
queue = PriorityQueue(0)
|
||||
queue.put((2, "second"))
|
||||
queue.put((1, "first"))
|
||||
queue.put((3, "third"))
|
||||
priority, value = queue.get()
|
||||
|
||||
\end{verbatim}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue