Discuss / Python / 作业

作业

Topic source

Eliefly

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

def by_name(L):
    return L[0]

def by_score(L):
    return L[1]

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

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

Eliefly

#2 Created at ... [Delete] [Delete and Lock User]
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

L2 = sorted(L,key=lambda t: t[0])
print(L2)

L2 = sorted(L,key=lambda t: t[1],reverse=True)
print(L2)

  • 1

Reply