Let's say my_list
is a list of datetime
objects. I understand that I can sort this list with the most recent dates first with:
sorted(my_list, reverse=True)
Similarly, if I have a list of tuples (datetime, str)
. Then I can sort this with most recent first by:
sorted(my_list, lambda x: x[0], reverse=True)
But what if I want to sort by datetime, most recent first, and break ties by sorting the str
"alphabetically"?
sorted(my_list, lambda x: x[0], x[1], reverse=True)
Now this will also sort the string in reverse alphabetical order. How do I fix it to do what I want?