sorting list of a sentence and number
<p>I have checked several of the answers on how to sort lists in python, but I can't figure this one out.</p>

<p>Let's say I have a list like this:
['Today is a good day,1', 'yesterday was a strange day,2', 'feeling hopeful,3']</p>

<p>Is there a way to sort by the number after each sentence? </p>

<p>I am trying to learn this stuff on my own, so I tried stuff like:</p>

<pre><code>def sortMyList(string):
    return len(string)-1

sortedList = sorted(MyList, key=sortMyList())
</code></pre>

<p>But of course it doesn't work becaue sortMyList expects one parameter.</p>

<p>This worked for me:</p>

<pre><code>sorted(myList, key=lambda x: x[-1])
</code></pre>

<p>If you need to go into double digits:</p>

<pre><code>sorted(myList, key=lambda x: int(x.split(',')[1]))
</code></pre>

python python-3.x