Here is some quality code that Alex Martelli posted on comp.lang.python [ post here ];
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 note to myself to use this class whenever I need a first in, first out stack. If you look at the whole thread you will notice lots of other suggestions to solve the original problem. I've copied this one because it is simple, clean, easy to understand and just plain great. All good reasons to program in Python.
10:56:43 AM
|