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)
原文:https://www.cnblogs.com/leader-one/p/12885160.html