title: Perform a descending numerical and then ascending alphabetical sort from a list of alphanumeric strings in Python
body: <p>I have a list of strings for which I would like to perform a descending numerical and then ascending alphabetical sort.</p>
  <p>For instance, the following list needs to be sorted:</p>
  <pre><code>['120d', '120a', '1080p', '1080a', '696p', '696z']
  </code></pre>
  <p>What is want as the output:</p>
  <pre><code>['1080a', '1080p', '696p', '696z', '120a', '120d']
  </code></pre>
  <p>What I get when I use sorted function of python:</p>
  <pre><code>['1080a', '1080p', '120a', '120d', '696p', '696z']
  </code></pre>
  <p>What I get when I use <a href="https://stackoverflow.com/questions/4836710/is-there-a-built-in-function-for-string-natural-sort">natsorted</a> (from this post) function of python:</p>
  <pre><code>['120a', '120d', '696p', '696z', '1080a', '1080p']
  </code></pre>
  <p>I would be glad if anyone can assist me or guide me on the right track. Thank you</p>
  <p>Simplified code:</p>
  <pre><code>from natsort import natsorted
  
  f = ['120d', '120a', '1080p', '1080a', '696p', '696z']
  print (&quot;ACTUAL:&quot;)
  print (f)
  print ()
  
  f_sorted = sorted(f)
  print (&quot;SORTED:&quot;)
  print (f_sorted)
  print ()
  
  f_natsorted = natsorted(f)
  print (&quot;NATSORTED:&quot;)
  print (f_sorted)
  print ()
  
  desired = ['1080a', '1080p', '696p', '696z', '120a', '120d']
  print (&quot;WANTED:&quot;)
  print (desired)
  </code></pre>