Having dictionary:
{'david': ['APP', 2], 'ala': ['PROD', 2], 'steven': ['DEV', 4], 'katya': ['SYS', 2]}
I want to sort it by prioritizing second element of list (descending) and then by first element of list (ascending). My desired output is:
>>> [('steven', ['DEV', 4]), ('david': ['APP', 2]), ('ala': ['PROD', 2]), ('katya': ['SYS', 2])]
The best idea i have:
x = sorted(x.items(), key=lambda elem: elem[1][1], reverse=True)
x.sort(key=lambda elem: elem[1][0])
>>> [('david', ['APP', 2]), ('steven', ['DEV', 4]), ('ala', ['PROD', 2]), ('katya', ['SYS', 2])]
Is there any function or approach from core python that would take into consideration sorting on the same object with values prioritizing, in my case if digits (digits are being sorted descending) are equal then look at strings like 'APP', 'DEV'... and sort them ascending by string?