title: How to implement own custom dict class in python
body: <p>I am learning classes in python and am fiddling around with creating my own version of <code>defaultdict</code> from <code>collections</code> module. Here's what I have tried:- </p>
  
  <pre><code>class Mydict(dict):
      def __missing__(self, key):
          self.key = []
          return []
  </code></pre>
  
  <p>Here's the output from interactive shell:-</p>
  
  <pre><code>&gt;&gt;&gt; d = Mydict()
  &gt;&gt;&gt; d['x']
  #outputs []
  &gt;&gt;&gt; d['x'].extend([1,2,3,4,5])
  &gt;&gt;&gt; print(d)
  # Outputs {}
  </code></pre>
  
  <p>I do not understand why does it not store the key <code>x</code> in the <code>d</code> object? What do I miss? </p>