November 29, 1997 | Fredrik Lundh
The following Stack class allows you to store any kind of data in a first-in, last-out fashion. Note that items are appended to the end of the internal list object; this means that both push and pop are relatively fast operations.
class Stack: def __init__(self): self.list =  def __len__(self): return len(self.list) def push(self, item): self.list.append(item) def pop(self): return self.list.pop() # default is last
In recent versions of Python, you can use collections.deque instead of a list object.