title: Python dictionary with enum as key
body: <p>Let's say I have an enum</p>
  <pre class="lang-py prettyprint-override"><code>class Color(Enum):
      RED = &quot;RED&quot;
      GREEN = &quot;GREEN&quot;
      BLUE = &quot;BLUE&quot;
  </code></pre>
  <p>I wanted to create a <code>ColorDict</code> class that works as a native python dictionary but only takes the <code>Color</code> enum or its corresponding string value as key.</p>
  <pre class="lang-py prettyprint-override"><code>d = ColorDict() # I want to implement a ColorDict class such that ...
  
  d[Color.RED] = 123
  d[&quot;RED&quot;] = 456  # I want this to override the previous value
  d[Color.RED]    # ==&gt; 456
  d[&quot;foo&quot;] = 789  # I want this to produce an KeyError exception
  </code></pre>
  <p>What's the &quot;pythonic way&quot; of implementing this <code>ColorDict</code> class? Shall I use inheritance (overriding python's native <code>dict</code>) or composition (keep a <code>dict</code> as a member)?</p>