Undo is a pretty common application functionality. I present a Python implementation where a History object is used to perform any action that may be undone. This object can go back and forth in the actions history. The idea is that, for every action, you provide one way to perform the action and one way to revert the action.

Implementation

The History class definition follows. An instance maintains a list of actions, each action being composed of a way to perform something and a way to revert it: