Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
09d9f86c
Commit
09d9f86c
authored
Jun 26, 2002
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add /F's PriorityQueue example
parent
ffd3a421
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
Doc/lib/libbisect.tex
Doc/lib/libbisect.tex
+19
-1
No files found.
Doc/lib/libbisect.tex
View file @
09d9f86c
...
...
@@ -61,7 +61,7 @@ The following functions are provided:
\end{funcdesc}
\subsection
{
Example
}
\subsection
{
Example
s
}
\nodename
{
bisect-example
}
The
\function
{
bisect()
}
function is generally useful for categorizing
...
...
@@ -81,3 +81,21 @@ breakpoints: 85 and up is an `A', 75..84 is a `B', etc.
>>> 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}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment