Discuss / Python / 问一个问题

问一个问题

Topic source

you_you_k

#1 Created at ... [Delete] [Delete and Lock User]
'''
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
def func(L):
    for x in L:
        if not isinstance(x,str):
            return x            
L = sorted(L,key =func)    
print(L)
'''
'''
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
def func(L):
    return L[0]
L = sorted(L,key = func)
print(L)
'''

为什么第一种写法,输出是从小到大排 第二个是从大到小排

第一种写法,是按成绩排的 第二种写法,是按姓名排的

你是不是看错了,if not isinstance


  • 1

Reply