title: What's the best way to initialize a dict of dicts in Python?
body: <p>A lot of times in Perl, I'll do something like this:</p>
  
  <pre><code>$myhash{foo}{bar}{baz} = 1
  </code></pre>
  
  <p>How would I translate this to Python? So far I have:</p>
  
  <pre><code>if not 'foo' in myhash:
      myhash['foo'] = {}
  if not 'bar' in myhash['foo']:
      myhash['foo']['bar'] = {}
  myhash['foo']['bar']['baz'] = 1
  </code></pre>
  
  <p>Is there a better way?</p>