title: How can I sort a list by numbers instead of string?
body: <p>I have this code:</p>
  
  <pre><code>import glob, os
  outdir = './output/'
  nstring = 'testdat_2014-12-31'
  nfilelist = sorted(glob.glob((outdir+'/*{}*.nc').format(nstring)))
  </code></pre>
  
  <p>from which I get <code>nfilelist</code>:</p>
  
  <pre><code>['testdat_2014-12-31-21_H1.nc',
   'testdat_2014-12-31-21_H10.nc',
   'testdat_2014-12-31-21_H11.nc',
   'testdat_2014-12-31-21_H12.nc',
   'testdat_2014-12-31-21_H2.nc',
   'testdat_2014-12-31-21_H3.nc',
   'testdat_2014-12-31-21_H4.nc',
   'testdat_2014-12-31-21_H5.nc',
   'testdat_2014-12-31-21_H6.nc',
   'testdat_2014-12-31-21_H7.nc',
   'testdat_2014-12-31-21_H8.nc',
   'testdat_2014-12-31-21_H9.nc']
  </code></pre>
  
  <p>The H1-H12 numbers at the end reflect how I want to sort it. But right now, H10-H12 is sandwiched in the middle. How can I sort from H1-H12?</p>
  
  <p>Regex isn't my strong suit and I'm unable to move forward.</p>
  
  <p>I tried splitting and got this far:</p>
  
  <pre><code>nfilelist[0].split('_')[-1].split('.')
  ['H1', 'nc']
  </code></pre>