title: How to match a python formatstring to elements in a list?
body: <p>I use Python and there's a list of file names of different file types. Text files may look like these:</p>
  
  <pre><code>01.txt
  02.txt
  03.txt
  ...
  </code></pre>
  
  <p>Let's assume the text files are all numbered in this manner. Now I want to get all the text files with the number ranging from 1 to 25. So I would like to provide a formatstring like <code>%02i.txt</code> via GUI in order to identify all the matching file names.</p>
  
  <p>My solution so far is a nested <code>for</code> loop. The outer loop iterates over the whole list and the inner loop counts from 1 to 25 for every file:</p>
  
  <pre class="lang-py prettyprint-override"><code>fmt = '%02i.txt'
  for f in files:
      for i in range(1, 25+1):
          if f == fmt % i:
              # do stuff
  </code></pre>
  
  <p>This nested loop doesn't look very pretty and the complexity is <em>O(n²)</em>. So it could take a while on very long lists. <strong>Is there a smarter/pythonic way of doing this?</strong></p>
  
  <p>Well, yes, I could use a regular expression like <code>^\d{2}\.txt$</code>, but a formatstring with <code>%</code> is way easier to type. </p>