This class implements a sorta circular stack. If you get the top item, it will pop off but be added to the bottom.
class CircularStack(list): def gettop(self): item = self.pop() self.append(item) return item