title: python deepcopy and shallow copy and pass reference
body: <p>A question about python deepcopy and shallow copy. </p>
  
  <p>the post at
  <a href="https://stackoverflow.com/questions/184710/what-is-the-difference-between-a-deep-copy-and-a-shallow-copy">What is the difference between a deep copy and a shallow copy?</a></p>
  
  <p>cannot help me. </p>
  
  <p>why e.g. 1 's sum is 6 not 10 ? </p>
  
  <h2>e.g.1 :</h2>
  
  <pre><code>kvps = { '1' : 1, '2' : 2 }
  theCopy = kvps.copy()  # both point to the same mem location ? 
  kvps['1'] = 5
  sum = kvps['1'] + theCopy['1']
  print sum
  </code></pre>
  
  <p>output sum is 6 </p>
  
  <h2>e.g.2 :</h2>
  
  <pre><code>aList = [1,2]
  bList = [3,4]
  kvps = { '1' : aList, '2' : bList }
  
  theCopy = kvps.copy()  # both point to the same mem location ? 
  kvps['1'][0] = 5
  sum = kvps['1'][0] + theCopy['1'][0]
  
  print sum
  </code></pre>
  
  <p>output sum is 10 </p>
  
  <h2>e.g.3 :</h2>
  
  <pre><code>import copy
  
  aList = [1,2]
  bList = [3,4]
  kvps = { '1' : aList, '2' : bList }
  
  theCopy = copy.deepcopy(kvps)
  kvps['1'][0] = 5
  sum = kvps['1'][0] + theCopy['1'][0]
  
  print sum
  </code></pre>
  
  <p>output sum is 6. </p>
  
  <h2>Also , e.g. 4</h2>
  
  <pre><code>kvps = { '1' : 1, '2' : 2 }    
  theCopy = dict(kvps)  #  theCopy hold a reference to kvps ?     
  kvps['1'] = 5  # should also change theCopy , right ?    
  sum = kvps['1'] + theCopy['1']    
  print kvps    
  print theCopy    
  print sum
  </code></pre>
  
  <p>its sum is 6 , if theCopy is a reference to kvps , it should be 10. </p>