Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
how to implement a queue-like container with sort function
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Steven D'Aprano, post: 5129605"] Unless the OP needs all the extra threading-related powers of the queue module, I'd just stick to a simple, single-threaded queue object. These easiest way to do that is with a deque, which is a double-ended queue. The threading Queue class is based on a deque, so this will be at least as fast: py> from collections import deque py> my_queue = deque([], 5) # maximum of five items py> my_queue.append(7) py> my_queue.append(3) py> my_queue.append(9) py> sorted(my_queue) [3, 7, 9] py> my_queue.append(2) py> my_queue.append(0) py> my_queue.append(4) py> my_queue deque([3, 9, 2, 0, 4], maxlen=5) py> sorted(my_queue) [0, 2, 3, 4, 9] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
how to implement a queue-like container with sort function
Top