title: How to make python class support item assignment?
body: <p>While looking over some code in <a href="http://greenteapress.com/complexity/html/thinkcomplexity003.html#toc13" rel="noreferrer">Think Complexity</a>, I noticed their <code>Graph</code> class assigning values to itself.  I've copied a few important lines from that class and written an example class, <code>ObjectChild</code>, that fails at this behavior.</p>
  
  <pre><code>class Graph(dict):
      def __init__(self, vs=[], es=[]):
          for v in vs:
              self.add_vertex(v)
  
          for e in es:
              self.add_edge(e)
  
      def add_edge(self, e):
          v, w = e
          self[v][w] = e
          self[w][v] = e
  
      def add_vertex(self, v):
          self[v] = {}
  
  class ObjectChild(object):
      def __init__(self, name):
          self['name'] = name
  </code></pre>
  
  <p>I'm sure the different built in types all have their own way of using this, but I'm not sure whether this is something I should try to build into my classes.  Is it possible, and how?  Is this something I shouldn't bother with, relying instead on simple composition, e.g. <code>self.l = [1, 2, 3]</code>?  Should it be avoided outside built in types?</p>
  
  <p>I ask because I was told "You should almost never inherit from the builtin python collections"; advice I'm hesitant to restrict myself to.</p>
  
  <p>To clarify, I know that <code>ObjectChild</code> won't "work", and I could easily <em>make</em> it "work", but I'm curious about the inner workings of these built in types that makes their interface different from a child of <code>object</code>.</p>