title: Increment items in nested python dict
body: <p>I have a nested Python Dict and I am trying to take values from a list and then iterate them into a Dict's values as such:</p>
  
  <pre><code>for row in rows:
    Dict[A][AA][AAA] += 1
  </code></pre>
  
  <p>However, when I print my dict, it appears to be adding all of the increments to all of the Dict entries. By which I mean that instead of this:</p>
  
  <pre><code>{KeyA:{KeyAA:{KeyAAA:5}}}
  {KeyB:{KeyBB:{KeyBBB:10}}}
  </code></pre>
  
  <p>I am getting this:</p>
  
  <pre><code>{KeyA:{KeyAA:{KeyAAA:15}}}
  {KeyB:{KeyBB:{KeyBBB:15}}}
  </code></pre>
  
  <p>I'm a bit stumped.</p>
  
  <p>EDIT:
  This is how the Dicts were created: 
  I first skim through a long table that contains a type classification. While I'm doing that, I create a new entry into the main Dict. At the same time, I'm collecting all of the unique classifications into a subDict so that I can add this to the main Dict later on:</p>
  
  <pre><code>Dict = {}
  subDict = {}
  for row in skimRows:
    Dict[row[0]] = {"Type":row[1],"Assoc":{}} # Save each ID and origin Type to Dict
    if item not in subDict: # Check to see if unique item already exists in subDict
      subDict[item] = 0
  </code></pre>
  
  <p>Here is evidently where I was going wrong. I was then taking the subDict and plunking this into the main Dict, not realising the inserted subDict was retaining its relationship to the original subDict object:</p>
  
  <pre><code>for key in Dict: # After initial iteration and Type collection, add new subDict to each Dict key
    Dict[key]["Assoc"] = subDict
  </code></pre>
  
  <p>SOLUTION:
  Per the correct answer below, I fixed it by adding .copy()</p>
  
  <pre><code>for key in Dict: # After initial iteration and Type collection, add new subDict to each Dict key
    Dict[key]["Assoc"] = subDict.copy()
  </code></pre>