abs是绝对值排序
list = [6,7,8,9,1,2,34]
list.sort()
print(list)
# 不改变原来的列表内容,生成一个新的列表
list2 = sorted(list)
print(list)
print(list2)
list2 = [6,8,-8,-4,2,3,4,7,8]
list2.sort()
print(list2)
list3 = sorted(list2,key=abs)
print(list3)
s = ['da','Ffsf','FSF','das']
print(s) #默认排序ascii码排序
print(sorted(s))
print(sorted(s,key=str.lower))
print(sorted(s,key=str.upper))
#执行结果
[1, 2, 6, 7, 8, 9, 34]
[1, 2, 6, 7, 8, 9, 34]
[1, 2, 6, 7, 8, 9, 34]
[-8, -4, 2, 3, 4, 6, 7, 8, 8]
[2, 3, -4, 4, 6, 7, -8, 8, 8]
['da', 'Ffsf', 'FSF', 'das']
['FSF', 'Ffsf', 'da', 'das']
['da', 'das', 'Ffsf', 'FSF']
['da', 'das', 'Ffsf', 'FSF']
来源:CSDN
作者:房渊
链接:https://blog.csdn.net/fangyuan1997/article/details/103483442