# 栗子 list排序
ls = [‘d.txt‘,‘a.xlxs‘,‘a.xlas‘,‘b.txt‘]
print(ls) #[‘d.txt‘, ‘a.xlxs‘, ‘a.xlas‘, ‘b.txt‘]
ls.sort(key=lambda x:x[0])
print(ls) #[‘a.xlxs‘, ‘a.xlas‘, ‘b.txt‘, ‘d.txt‘]
ls.sort(key=lambda x:x[4])
print(ls) #[‘a.xlas‘, ‘b.txt‘, ‘d.txt‘, ‘a.xlxs‘]
students = [(‘john‘,‘A‘,15),(‘jane‘,‘B‘,12),(‘dave‘,‘B‘,10)]
print(sorted(students,key=lambda s:s[2])) #[(‘dave‘, ‘B‘, 10), (‘jane‘, ‘B‘, 12), (‘john‘, ‘A‘, 15)]
#栗子