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>The answer is easy if the data looks like in your question. If the data is more complex you will have to give the <code>sort</code> method a key which contains only characters from the alphabet.</p>

<pre><code>data =  ["34b", "2a5t", "2a5s", "abcd"]
data.sort(key=lambda x: ''.join(c for c in x if c.isalpha()))
print(data)
</code></pre>

<p>This will give you <code>['abcd', '2a5s', '2a5t', '34b']</code>.</p>

<p>If you want to see how the constructed key looks like you can check it like this:</p>

<pre><code>for value in data:
    print(value, ''.join(c for c in value if c.isalpha()))

34b b
2a5t at
2a5s as
abcd abcd
</code></pre>

python