使用sorted()函数以及reverse参数可以对元组进行从大到小的排序。
例如:
tup = (3, 1, 4, 2, 5)sorted_tup = sorted(tup, reverse=True)print(sorted_tup)输出:
[5, 4, 3, 2, 1]还可以使用内置的sorted()函数结合lambda表达式进行排序:
tup = (3, 1, 4, 2, 5)sorted_tup = sorted(tup, key=lambda x: -x)print(sorted_tup)输出:
[5, 4, 3, 2, 1] 
