Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

January 16, 2002

Quality Code

Here is some quality code Alex Martelli posted on comp.lang.python;

class fifo:
    def __init__(self):
        self.data = []
        self.first = 0
    def head(self):
        return self.data[self.first]
    def pop(self):
        self.first += 1
        if self.first > len(self.data)/2:
            self.data = self.data[self.first:]
            self.first = 0
    def append(self, value):
        self.data.append(value)

I'm posting it here as a mental note to myself to use this class whenever I need a first in, first out stack.

Posted by Andy Todd at January 16, 2002 09:31 AM

Comments