+ 1

Sort list of lists in Py

I'm working in a analysis project, I have a list like this, a = [ ["hi", 15], ["Hello", 20], ["Hey", 10] ] I need to sort this list under the second element of the list, Like this, a = [ ["Hello", 20], ["hi", 15], ["Hey", 10] ] The list need to be sorted under those numbers. So far I tried, a = sorted(a[1]) It didn't worked in the way I expected. Give me a solution please.

29th Sep 2018, 3:29 PM
Hemath Kumar
Hemath Kumar - avatar
1 Respuesta
+ 3
a.sort(key=lambda x: int(x[1]))
29th Sep 2018, 3:39 PM
JME