You can reverse the sort of one of the columns if either of the columns is numeric, or can be expressed as numbers as well. You can then simply negate the numeric column to reverse the sort for that column.
If the t_l[-1]
column is numeric, use:
sorted(t_l, key=lambda i: (-i[-1], i[1]))
(using different names for the input list and the lambda
argument reduces confusion)
If that column is not numeric but the other one is, you can still use the same trick, but need to reverse the whole sort:
sorted(t_l, key=lambda i: (i[-1], -i[1]), reverse=True)
Single-character columns can be made numeric by using the ord()
function; using ord()
will result in the same sorting order, but since it is numeric you can now reverse it:
sorted(t_l, key=lambda i: (-ord(i[-1]), i[1]))