Python如何同个变量多个属性的操作 ?


题干: 若有如下结构的内容: (格式: 元素序号, 变量值, 状态)

编程 python 算法 数组

藤和艾莉欧 10 years, 6 months ago

问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

Your Answer