title: Can a regular expression be used as a key in a dictionary?
body: <p>I want to create a dictionary where the keys are regular expressions:</p>
  
  <pre><code>d = {'a.*': some_value1, 'b.*': some_value2}
  </code></pre>
  
  <p>Then, when I look into the dictionary:</p>
  
  <pre><code>d['apple']
  </code></pre>
  
  <p>I want apple <code>'apple'</code> to be matched against the keys which are regular expressions. If there is a complete match with a key/regular-expression then the corresponding value should be returned.</p>
  
  <p>For example <code>'apple'</code> matches with the regular expression <code>'a.*'</code> completely, and so, <code>some_value1</code> should be returned.</p>
  
  <p>Of course, all of this assumes that the regular expression keys do not conflict (i.e. two keys should not both match the same string exactly). Let's say I can manually take care of this requirement when building my keys.</p>
  
  <p>Is this possible in Python? If so, it would be quite an elegant and powerful construct!</p>