I decided to spend some time in Practice mode and have to say that it´s been a very good decision. I had to reread the documentation of many functions and methods that I thought I knew everything about them, but it resulted that there´s always something new to learn.
So, my question is related to this mission: https://app.dataquest.io/m/1018/lists/20/sorting-lists-of-lists-ii
I´ve come out with the following solution:
def sort_index(a_list): a_list.sort() a_list.sort(key=lambda student: student, reverse=True)
And tried it with a sample list
It worked as expected: the students were sorted by their grades in descending order while in alphabetical order of names inside each grade group.
But my answer wasn´t accepted by the answer checking machine.
The solution sorts for the first time also using the
def sort_index(a_list): a_list.sort(key=lambda student: student) a_list.sort(key=lambda student: student, reverse=True)
although in my opinion when no key is passed the default sort should work by the first character of inner lists and if so, both solutions work identically. Could there be some specific cases when the output won´t be identical? Or, is it just the way the answer checking machine works and my answer is also correct?