I need to sort the below list :
[('Elijah', 51), ('Chloe', 144), ('Elizabeth', 485), ('Matthew', 485), ('Natalie', 207), ('Jayden', 390)] It should be sorted based on the no. And if there are any two similar no's it is sorted alphabetically according to the name. The final ans should be
[('Elizabeth', 485), ('Matthew', 485), ('Jayden', 390), ('Natalie', 207), ('Chloe', 144), ('Elijah', 51)]. I am not able to understand the method given by the author. He wrote:
scores.sort(key=lambda x: (-x[1],x[0])) print(scores) In this scores refer to the above given list. Can anyone explain me what exactly happens.
keydoes, whatlambdais, whatx[1]is, or why the-? Or do you want to know how exactly it works "under the hood"?