List List List

1

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']]
    
asked by anonymous 30.11.2015 / 19:42

2 answers

0

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])
    
30.11.2015 / 19:49
0
#!/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. :)

    
30.11.2015 / 19:50