title: How do I do advanced Python hash autovivification?
body: <p>This question is about implementing the full Perl autovivification in Python. I know similar questions were asked before and so far the best answer is in "<a href="https://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/652284#652284">What is the best way to implement nested dictionaries in Python?</a>" . However, I'm looking to do this:</p>
  
  <pre><code>a['x']['y'].append('z')
  </code></pre>
  
  <p>without declaring <code>a['x']['y'] = []</code> first, or rather, not declaring <code>a['x'] = {}</code> either. (Note in Perl you can do <code>push @{$a-&gt;{x}{y}}, 'z';</code>.) </p>
  
  <p>I know <code>dict</code> and <code>list</code> classes sorta don't mix, so this is hard, but I'm interested in seeing if someone has an ingenious solution probably involving creating an inherited class from <code>dict</code> but defined a new <code>append</code> method on it? </p>
  
  <p>I also know this might throw off some Python purists who will ask me to stick with Perl. But, even just for a challenge, I'd like to see something.</p>