Discuss / Python / 分别按名字排序&分数从高到低排序:

分别按名字排序&分数从高到低排序:

Topic source
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_name(t):
	m=t[0]
	return m


def by_score(t):
	n=-t[1]
	return n


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


  • 1

Reply