-1

I have a 2d list with all of the lists having the same format and I want to arrange it so it is going up in numerical order. Here is the list:

list = [["a", -50], ["b", 23], ["c", 5], ["d", 44], ["e", 23]]

How do i end up with something which prints

data_list = [["a", -50], ["c", 5], ["b", 23], ["e", 23], ["d", 44]]

I'm avoiding using .sort() or any other built in functions as I want to keep the strings with the appropriate number

Deps
  • 555
  • 1
  • 4
  • 12

1 Answers1

0

You can use builtins and still keep the association. E.g.:

data_list = sorted(lst, key=lambda x: x[1]) 
Mureinik
  • 297,002
  • 52
  • 306
  • 350