title: Optimized pattern searching algorithm in Python
body: <p>I need to search a regular expression pattern from a huge list of file names. So, time complexity is very important factor for me. Currently, I am using this code to find the pattern:</p>
  
  <pre><code>for item in mylist:
      if reobj.match(name):
          // do some stuff and return the result
  </code></pre>
  
  <p>So, I think reobj.match call is taking O(n^2) time. Can anyone suggest me any other pattern searching algorithm in python to make the operation faster?</p>
  
  <p>Please note that the list is not sorted, so can't do a binary search here.</p>
  
  <p>Few other ideas I have is related to maintain an index on file names. But again the concern there is with the regular expression patterns. How can I index on patterns?</p>