首页 > 技术文章 > python中的排序

elpsycongroo 2018-11-04 01:36 原文

demo:

#coding:utf-8
from functools import cmp_to_key

def cmp1(x,y):
    if x[0]==y[0]:
        return y[1]-x[1]
    else:
        return x[0]-y[0]

A=[[1,2],[3,1],[2,2],[2,1]]
A=sorted(A,key=cmp_to_key(cmp1),reverse=True)
print(A)

 

推荐阅读