l=sorted([36, 5, -12, 9, -21]) print(l) ''' [-21, -12, 5, 9, 36] ''' l=sorted([36, 5, -12, 9, -21],key=abs) print(l) ''' [5, 9, -12, -21, 36] '''
# 按照元祖里的key的name首字母
lis = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
sorted_lis=sorted(lis,key=lambda x:x[0])
print(sorted_lis)
'''
[('Adam', 92), ('Bart', 66), ('Bob', 75), ('Lisa', 88)]
'''
标签:12,21,36,lis,print,sorted,排序 From: https://www.cnblogs.com/haha1988/p/17537956.html