title: What's the most idiomatic way to implement a stack for `dictionary` type in `Python`?
body: <p>I am trying to implement a stack machine in <code>Python</code> using <code>list</code> as my stack and <code>dictionary</code> as current machine state. But it doesn’t work as planned. After some debugging I found out that when I store machine state into stack, and then change it state, the stored state changes also.
  Here is an example demonstrating my problem:</p>
  
  <pre><code>MyStack = []        
  myState = {}
  myState['param'] = '1'
  MyStack.append(myState)
  myState['param'] = '2'
  MyStack.append(myState)
  myState['param'] = '3'
  MyStack.append(myState) 
  print(MyStack.pop())
  print(MyStack.pop())
  print(MyStack.pop())
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>{'param': '3'}
  {'param': '3'}
  {'param': '3'}
  </code></pre>
  
  <p>And not </p>
  
  <pre><code>{'param': '3'}
  {'param': '2'}
  {'param': '1'}
  </code></pre>
  
  <p>As I would think</p>
  
  <p>Evidently, <code>Python</code> stores in <code>list</code> not copies of my <code>dictionary</code>, but references to it. So, all stacked items in reality are the same <code>myState</code> object. When I’ve got this, I walked the problem around by using <code>dictionary.copy()</code> method like so: <code>MyStack.append(myState.copy())</code>. But it seems a bit unnatural.</p>
  
  <p>So, the question is: which is the most idiomatic way to implement a stack for <code>dictionary</code> type in <code>Python</code>?</p>