title: How do I create a default dictionary of dictionaries
body: <p>I am trying to write some code that involves creating a default dictionary of dictionaries. However, I have no idea how to initialise/create such a thing. My current attempt looks something like this:</p>
  
  <pre><code>from collections import defaultdict
  inner_dict = {}
  dict_of_dicts = defaultdict(inner_dict(int))
  </code></pre>
  
  <p>The use of this default dict of dictionaries is to for each pair of words that I produce from a file I open (e.g. [['M UH M', 'm oo m']] ), to set each segment of the first word delimited by empty space as a key in the outer dictionary, and then for each segment in the second word delimited by empty space count the frequency of that segment.</p>
  
  <p>For example</p>
  
  <pre><code>[['M UH M', 'm oo m']] 
  (&lt;class 'dict'&gt;, {'M': {'m': 2}, 'UH': {'oo': 1}})
  </code></pre>
  
  <p>Having just run this now it doesn't seem to have output any errors, however I was just wondering if something like this will actually produce a default dictionary of dictionaries.</p>
  
  <p>Apologies if this is a duplicate, however previous answers to these questions have been confusing and in a different context.</p>