'Sort a list of lists using descending order, and then if there is a tie breaker, use descending order on another index in python
master_list = [["Hi", 2.00],["Hey", 6.01],["Hello", 9.56], ["How", 6.01]]
master_list.sort(key=lambda x: -(x[1], -x[0]))
I tried using this function to sort the master_list in descending order by the number, and if there is a tie, descending order by the string. However, I get the error "TypeError: bad operand type for unary -: 'str' I don't know what I am doing wrong to get this error. How do I sort the list?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
