我有一个类似这样的列表:
list_results=[('Horror', 2), ('Romance', 2), ('Comedy', 2), ('History', 2), ('Adventure', 1), ('Action', 3)]
我希望将数字按降序排列,如果数字相同,则按名称升序排列。
我尝试了以下代码:
sortlist=sorted(list_results,key=lambda x:(x[1],x[0]))
我想要做的是反过来,但我不知道该怎么做。
我要找的答案是:
[('Action', 3), ('Comedy', 2) ,('History', 2),('Horror', 2), ('Romance', 2), ('Adventure', 1), ]