title: Multiple levels of 'collection.defaultdict' in Python
body: <p>Thanks to some great folks on SO, I discovered the possibilities offered by <code>collections.defaultdict</code>, notably in readability and speed. I have put them to use with success.</p>
  
  <p>Now I would like to implement three levels of dictionaries, the two top ones being <code>defaultdict</code> and the lowest one being <code>int</code>. I don't find the appropriate way to do this. Here is my attempt:</p>
  
  <pre><code>from collections import defaultdict
  d = defaultdict(defaultdict)
  a = [("key1", {"a1":22, "a2":33}),
       ("key2", {"a1":32, "a2":55}),
       ("key3", {"a1":43, "a2":44})]
  for i in a:
      d[i[0]] = i[1]
  </code></pre>
  
  <p>Now this works, but the following, which is the desired behavior, doesn't:</p>
  
  <pre><code>d["key4"]["a1"] + 1
  </code></pre>
  
  <p>I suspect that I should have declared somewhere that the second level <code>defaultdict</code> is of type <code>int</code>, but I didn't find where or how to do so.</p>
  
  <p>The reason I am using <code>defaultdict</code> in the first place is to avoid having to initialize the dictionary for each new key.</p>
  
  <p>Any more elegant suggestion?</p>
  
  <p>Thanks pythoneers!</p>