-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])
0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Please Add explanation.
It just needs to add reverse=True to the end to receive expected answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.