1. 基本用法
1)仅对于list类型的数据
a.sort() 按升序
a.sort(reverse = True) 按降序
2)对于所有可排序类型的数据
sorted(a, reverse = True)
2. 自定义排序函数
a = ((1,2), (3,1), (2,7))
b = sorted(a, key=lambda a: a[1])# b = [(3, 1), (1, 2), (2, 7)]
3. sort内核
python的内置函数sort实际上是应用了归并排序的思想实现的。