Discuss / Python / 解答

解答

Topic source

Kanvisen

#1 Created at ... [Delete] [Delete and Lock User]

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
def by_name(x):
return x[0].lower()
L2 = sorted(L, key=by_name)
print(L2)

def by_score(x):
return x[1]
L2 = sorted(L, key=by_score)
print(L2)

bzny虫

#2 Created at ... [Delete] [Delete and Lock User]

直接x[1]就是从低到高排了,可以乘个-1


  • 1

Reply