title: Regular expression dictionary in python
body: <p>Is it possible to implement a dictionary with keys as regular expressions and actions (with parameters) as values?</p>
  
  <p>for e.g. </p>
  
  <ol>
  <li><code>key = "actionname 1 2", value = "method(1, 2)"</code></li>
  <li><code>key = "differentaction par1 par2", value = "appropriate_method(par1, par2)"</code></li>
  </ol>
  
  <p>User types in the key, i need to execute the matching method with the parameters provided as part of user input.</p>
  
  <p>It would be great if we can achieve the lookup in <code>O(1)</code> time, even if its not possible atleast i am looking for solutions to solve this problem.</p>
  
  <p>I will be having few hundred regular expressions (say <code>300</code>) and matching parameterized actions to execute.</p>
  
  <p><strong>I can write a loop to achieve this, but is there any elegant way to do this without using a for loop?</strong></p>
  
  <p>Related question: <a href="https://stackoverflow.com/questions/260056/hashtable-dictionary-map-lookup-with-regular-expressions">Hashtable/dictionary/map lookup with regular expressions</a></p>