title: How to implement an undo()-Method for a List-Class in Python
body: <p>Im kinda new with python and I got a task to create a class "UndoList" (type list) with an undo()-method. This method should undo typical list-operations like, append, insert, remove...</p>
  
  <pre><code>&gt;&gt;&gt; ul = UndoList([1,2,3])
  &gt;&gt;&gt; ul.append(4), print(ul), undo(ul), print(ul)
  [1,2,3,4]
  [1,2,3]
  &gt;&gt;&gt; ul.remove(3), print(ul), undo(ul), print(ul)
  [1,2]
  [1,2,3]
  ...
  </code></pre>
  
  <p>This undo()-method should only undo one operation (as u can see in the example). My teacher gave me the hint, to save the value of the list in the instance before every operation.</p>
  
  <p>This is my class:</p>
  
  <pre><code>class UndoList(list):
  
     def __init__(self, lis):
         list.__init__(self, lis)
         self.lis = []
  
     def __append__(self, lis):
         list.__add__(self, lis)
         return lis
  
     def undo(self):
         return self
  
  a1 = UndoList([1,2,3])
  print(a1), a1.append(4), print(a1)   #[1,2,3] [1,2,3,4]
  a1.undo(), print(a1)                 #[1,2,3,4]
  </code></pre>
  
  <p>So now my question: how can i create an instance in my class to save my actual list before I do any operation? And is it possible to just retrun this instance in my undo-method?</p>
  
  <p>Thanks!</p>