how to implement a queue-like container with sort function

Terry Reedy tjreedy at
Fri Nov 29 03:31:36 CET 2013

On 11/28/2013 8:54 PM, iMath wrote:
> I want to a fixed length list-like container, it should have a sorted()-like function that I can use to sort it,I think there should also a function I can use it to detect whether the numbers of items in it reaches the length of the container , because if the numbers of items in it reaches the length(fixed) of the container,I want to process the data in it .Is there a container in Python like this ?If not, what base container should be used to implement such container?
> the container is similar to queue ,but queue doesn't have a sort function

For single thread use, subclass list, add a new .put method that checks 
the list size and either does self.append or self.sort(); process(list).

For multiple threads, you need the queue module, which has extra 
features (and baggage). A PriorityQueue yields items in sorted order. 
Subclass it and override .put to either call the original .put or start 
a process thread.

Terry Jan Reedy

More information about the Python-list mailing list