title: Many-to-one mapping (creating equivalence classes)
body: <p>I have a project of converting one database to another. One of the original database columns defines the row's category. This column should be mapped to a new category in the new database.</p>
  
  <p>For example, let's assume the original categories are:<code>parrot, spam, cheese_shop, Cleese, Gilliam, Palin</code></p>
  
  <p>Now that's a little verbose for me, And I want to have these rows categorized as <code>sketch, actor</code> - That is, define all the sketches and all the actors as two equivalence classes.</p>
  
  <pre><code>&gt;&gt;&gt; monty={'parrot':'sketch', 'spam':'sketch', 'cheese_shop':'sketch', 
  'Cleese':'actor', 'Gilliam':'actor', 'Palin':'actor'}
  &gt;&gt;&gt; monty
  {'Gilliam': 'actor', 'Cleese': 'actor', 'parrot': 'sketch', 'spam': 'sketch', 
  'Palin': 'actor', 'cheese_shop': 'sketch'}
  </code></pre>
  
  <p>That's quite awkward- I would prefer having something like:</p>
  
  <pre><code>monty={ ('parrot','spam','cheese_shop'): 'sketch', 
          ('Cleese', 'Gilliam', 'Palin') : 'actors'}
  </code></pre>
  
  <p>But this, of course, sets the entire tuple as a key:</p>
  
  <pre><code>&gt;&gt;&gt; monty['parrot']
  
  Traceback (most recent call last):
    File "&lt;pyshell#29&gt;", line 1, in &lt;module&gt;
      monty['parrot']
  KeyError: 'parrot'
  </code></pre>
  
  <p>Any ideas how to create an elegant many-to-one dictionary in Python?</p>