Simple Queue Class

November 29, 1997 | Fredrik Lundh

The Queue class is similar to Stack, but it stores data in a first-in, first-out fashion.

Example: The Queue implementation (for Python 1.5.2 and later)
class Queue:

    def __init__(self):
        self.list = []

    def __len__(self):
        return len(self.list)

    def put(self, item)

    def get(self)
        return self.list.pop(0)

Recent versions of Python provide a deque class, which provides a more efficient implementation.

See also

Queue definition at NIST.


A Django site. rendered by a django application. hosted by webfaction.