I have list of lists:
unsorted_list = [[3, 'A'], [1, 'A'], [3, 'B'], [4, 'B'], [4, 'A'], [2, 'C']]
And I want to get:
sorted_list = [[4, 'A'], [4, 'B'], [3, 'A'], [3, 'B'], [2, 'C'], [1, 'A']]
List is sorted in descending order on first element. If first elements are equal then is sorted on second element but in alphabetical order (ascending)
So far I got idea to sort it like that
unsorted_list.sort(key=lambda element: (element[0], element[1]), reverse=True)
this will sort list by two elements but in descending order.
Question: Is there way to sort the list of lists by first element (in descending order), and if first elements are equal then by second element in ascending order?
Edit: First elem is always int and second is a string Thx for all the answers.