Discuss / Python / 交作业

交作业

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

def by_score(t):
    return -t[1]  #返回分数的负值。这样就不需要逆序了
L3=sorted(L,key=by_score)
print(L3)

  • 1

Reply