Answers
问1:
def testa():
l = [(1, 25, 'good'),
(2, -7, 'bad'),
(3, 5, 'good'),
(4, 98, 'good')]
for x, y, z in sorted(l, key=lambda x:x[1]):
print z
问2:
import math
def testb(xi):
l = [(1, 98, 'good'),
(2, 4, 'bad'),
(3, 9, 'good')]
# key值=开方后加系数?
for x, y, z in sorted(l, key=lambda x:(math.sqrt(x[1])+xi)):
print z
testb(3)
sinaper
answered 10 years, 6 months ago