I'm doing some practice on Dataquest.
Here's the exercise:
Create a function, sort, that:
- Takes as input a list of lists.
- Orders the outer list by the third element in the inner lists in descending order.
- Resolves ties by sorting by the first one in ascending order.
- Modifies the input in place..
What I've done:
def sort_index(some_list):
some_list.sort(key=lambda x: x[2], reverse=True)
some_list.sort(key=lambda x: x[0])
The output:
- Function sort_index did not correctly modify the value of argument number 1.
Can someone explain to me why it worked when I reversed lines 1 and 2:
def sort_index(some_list):
some_list.sort(key=lambda x: x[0])
some_list.sort(key=lambda x: x[2], reverse=True)