Python之多级排序

import functools
# 默认为升序


def cmp(a, b):
    if a < b:
        return -1
    else:
        return 1

# 第一个元素升序,第二个元素降序


def mycmp(a, b):
    if a[0] == b[0]:
        return -cmp(a[1], b[1])
    else:
        return cmp(a[0], b[0])


x = []

for i in range(6):

    s = input().split(sep=' ')

    x = x+[(int(s[0]), int(s[1]))]

x.sort(key=functools.cmp_to_key(mycmp))

print(x)

  

posted @ 2020-05-13 21:55  林登万将军!  阅读(492)  评论(0)    收藏  举报