Discuss / Python / 这个可以

这个可以

Topic source

綾之桜

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]


# 按名字排序:
def by_name(t):
    return t[0]


L1 = sorted(L, key=by_name)
print(L1)


# 成绩从高到低排序:
def by_score(t):
    return -t[1]


L2 = sorted(L, key=by_score)
print(L2)


  • 1

Reply