how to sort items in a list alphabetically by the letters in their respective names.
<p>I am trying to sort values in a list by the letters in their name: I want, for example,  ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>

<p>Assuming your format is always number followed by letter, you need to give the sort method a specific key to sort by: in this case you want to sort by the last character. A lot of the other answers are just sorting your list alphabetically using the number followed by letter whereas I get the feeling you only want to sort by the letter. This is one possible way:</p>

<pre><code> s = ['9d', '12a', '1e']
 sorted_s = sorted(s, key=lambda x:x[-1])   # sorts by the last character of every entry
</code></pre>

<p>This will return:</p>

<pre><code>['12a', '9d', '1e']
</code></pre>

python