title: Natural sorting of a list in Python3
body: <p>I am trying to sort a list: </p>
  
  <pre><code>[
      '[fc] EDW Ratio (10 degrees)', 
      ' [fc] EDW Ratio (45 degrees)', 
      ' [fc] EDW Ratio (60 degrees)', 
      ' [fc] EDW Ratio (25 degrees)', 
      ' [fc] EDW Ratio (20 degrees)', 
      ' [fc] EDW Ratio (30 degrees)', 
      ' [fc] EDW Ratio (15 degrees)', 
      ' [fc] EDW output factor (60 degrees)', 
      ' [fc] Quality index'
  ]
  </code></pre>
  
  <p>using the first part of the accepted answer <a href="https://stackoverflow.com/questions/5967500/how-to-correctly-sort-a-string-with-a-number-inside">here</a>: </p>
  
  <p>But the list is ending up like this:</p>
  
  <pre><code>[
      ' [fc] EDW Ratio (15 degrees)', 
      ' [fc] EDW Ratio (20 degrees)', 
      ' [fc] EDW Ratio (25 degrees)', 
      ' [fc] EDW Ratio (30 degrees)', 
      ' [fc] EDW Ratio (45 degrees)', 
      ' [fc] EDW Ratio (60 degrees)', 
      ' [fc] EDW output factor (60 degrees)', 
      ' [fc] Quality index', 
      '[fc] EDW Ratio (10 degrees)'
  ]
  </code></pre>
  
  <p>whereas I want <strong><em>EDW Ratio (10 degrees)</em></strong> to end up at the start of the list after sorting (index position 0). </p>
  
  <p>How can this be done?</p>
  
  <p>My code includes the following:</p>
  
  <pre><code>#
  # Method to define natural sorting used to sort lists
  #
  def atoi(text):
      return int(text) if text.isdigit() else text
  
  def natural_keys(text):
      '''
      alist.sort(key=natural_keys) sorts in human order
      http://nedbatchelder.com/blog/200712/human_sorting.html
      (See Toothy's implementation in the comments)
      '''
      return [ atoi(c) for c in re.split(r'(\d+)', text) ]
  
      .
      .
      .
  
  
      tname_list = test_names.split(",") # this outputs the exact first (unsorted) list shown above
  
      tname_list.sort(key=natural_keys) # use human sorting defined above. This outputs the second list shown above.
  </code></pre>