how to implement a queue-like container with sort function

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Nov 29 05:53:11 CET 2013


iMath wrote:
> the container is similar to queue ,but queue doesn't have a sort  function 

You can use a list as a queue. If you have a list l, then
l.append(x) will add an item to the end, and l.pop(0) will
remove the first item and return it.

Then you just need to check the length of the list before
adding an item, and if it's full, do something to process
the items first.

You can encapsulate all this inside a class if you want,
but that's optional.

-- 
Greg



More information about the Python-list mailing list