I have the following list of lists:
lista = [['a', '1'], ['c', '3'], ['b', '2']]
And I want to sort this list according to the numbers, that is, I want it to look like this:
listaOrdenada = [['a','1'], ['b','2'], ['c','3']]
I have the following list of lists:
lista = [['a', '1'], ['c', '3'], ['b', '2']]
And I want to sort this list according to the numbers, that is, I want it to look like this:
listaOrdenada = [['a','1'], ['b','2'], ['c','3']]
You can use the sorted
function and pass as the second parameter to key that will be sorted
listaOrdenada = sorted(lista, key = lambda x: x[1])
#!/usr/bin/python
listaOrdenada = [['a','1'], ['c','3'], ['b','2']]
print "List : ", sorted(listaOrdenada,key=lambda l:l[1], reverse=False)
You can use lambda too. :)