sort方法改变原纪录,按照ascii值排序
lst = ['A', 'C', 'b', 'a', 'c', 'd', 'B', 'D']
lst.sort()
print(lst)
lst = ['A', 'C', 'b', 'a', 'c', 'd', 'B', 'D']
lst.sort(reverse=True)
print(lst)
print(lst.sort(reverse=True))
sorted(list),函数不改变原纪录
lst = ['A', 'C', 'b', 'a', 'c', 'd', 'B', 'D']
print(sorted(lst))
lst = ['A', 'C', 'b', 'a', 'c', 'd', 'B', 'D']
print(sorted(lst, reverse=True))
lst = [('b', 2), ('a', 1), ('c', 2), ('d', 4), ('c', 5)]
lst.sort(key=lambda x: (x[1], -ord(x[0])))
print(lst)
反转列表 reverse 与 [::-1]
lst = ['a', 'c', 1, 9]
lst.reverse()
print(lst)