title: Reversing a Stack in Python
body: <p>To reverse a stack:</p>
  
  <ol>
  <li>I made a empty temporary stack</li>
  <li>I used <code>tempstack.push(stack.pop())</code></li>
  <li>and then renamed it to <code>stack = tempstack</code></li>
  </ol>
  
  <p>but it doesn't seem to work. Any idea why?</p>
  
  <p>To call this, I want to use just <code>reverse(stack)</code>, not <code>stack = reverse(stack)</code>.</p>
  
  <pre><code>def reverse(stack):
      new_stack = Stack()
      while not stack.is_empty():
          new_stack.push(stack.pop())
      stack = new_stack
  </code></pre>