class Manage: def __init__(self): self.data = [18, 93, 3, 82, 76, 5, 9] self.commandStack = [] def display(self): for x in self.data: print x, "\t", print def run(self): while 1: cmd = raw_input("Type a command: ") if cmd == "quit" or cmd == "exit": break elif cmd == "print": self.display() elif cmd == "undo": cmd = self.commandStack[0] self.commandStack.pop(0) cmd.undo(self.data) elif cmd == "remove": cmd = RemoveCommand() cmd.execute(self.data) self.commandStack = [cmd] + self.commandStack class Command: def __init__(self, n): self.name = n def execute(self, data): pass def undo(self): pass def __repr__(self): return self.name class RemoveCommand(Command): def __init__(self): Command.__init__(self, "Remove") self.key = int(raw_input("Type number to remove: ")) def undo(self, data): data.insert(self.key) def execute(self, data): print "Removing: ", self.key data.remove(self.key) if __name__ == "__main__": man = Manage() man.run()