[Python-checkins] python/dist/src/Doc/lib libbisect.tex,1.10,1.11
montanaro@users.sourceforge.net
montanaro@users.sourceforge.net
Tue, 25 Jun 2002 22:07:31 -0700
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv26247
Modified Files:
libbisect.tex
Log Message:
add /F's PriorityQueue example
Index: libbisect.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libbisect.tex,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** libbisect.tex 6 Jul 2001 19:28:48 -0000 1.10
--- libbisect.tex 26 Jun 2002 05:07:28 -0000 1.11
***************
*** 62,66 ****
! \subsection{Example}
\nodename{bisect-example}
--- 62,66 ----
! \subsection{Examples}
\nodename{bisect-example}
***************
*** 81,83 ****
--- 81,101 ----
>>> 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}