fifo queue

Alex Martelli aleax at mac.com
Sun Mar 18 19:34:25 EDT 2007


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

> Unless the queue is really large, just use the pop operation to get
> stuff off the top of the queue.  That causes O(n) operations but it
> should be fast if n is small.
> 
>     class queue(list):
>         push = append
>         def pop(self):
>             return list.pop(self,0)
> 
> should do about what you wrote.

If it IS large, then:

import collections
class queue(collections.deque):
  push = collections.deque.append
  pop = collections.deque.popleft

could be even better.


Alex



More information about the Python-list mailing list