According to Python documentation:
The built-in sorted() function is guaranteed to be stable. A sort is stable if it guarantees not to change the relative order of elements that compare equal — this is helpful for sorting in multiple passes (for example, sort by department, then by salary grade).
Therefore, an easy way to do it will be doing a two-pass sorting:
sorted(theList, key = lambda x:x[1])
sorted(theList, key = lambda x:x[0], reverse = True)
Or if you really want a one-liner, you can do this:
sorted(thisList, key = lambda x:x[0] * 26 - (ord(x[1]) - ord('a')), reverse = True)
This one-liner assumes that all the characters are lowercase. What it does is that it makes each two consecutive numbers have a step of 26 instead of 1, and the characters a-z are mapped to 0-25, as a finer step. Since the characters are ascending order, we subtract it from the scaled number value.
This one-liner is kind of a hack, since it wouldn't work if the x[1]
has no range (i.e. also a number)