-3

I have a list as follow:

list1 = [['10', 'John', 'python'], ['1', 'Sara', 'java'], ['3','Tom', 'C']]

and as sorted result I expect following outpt:

3 Tom C
1 Sara Java
10 John python

in fact I want to sort it base on second parameter in internal list. This code does not work:

sort1 = sorted(list1, key=lambda x: x[0][1])
Babak Memar
  • 37
  • 2
  • 12

1 Answers1

1

try this:

sort1 = sorted(list1, key=lambda x: x[1])

that [1] will be enough because it will iterate through the list and in each iteration x will be the inner list.

Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59