利用lambda表达式对元祖列表中排序

li 如下
在这里插入图片描述

// sort according to the second value

li.sort(key=lambda x:x[1], reverse=True)
for i in range(0,20):
    key,value = li[i]
    print('{:<3}{:<6}{:>5}'.format(i+1,key,value))

猜你喜欢

转载自blog.csdn.net/weixin_44227389/article/details/113872962