python的sort有个key参数
>>> a=range(10)
>>> b=a[::-1]
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> b
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>> c=zip(a,b)
>>> c
[(0, 9), (1, 8), (2, 7), (3, 6), (4, 5), (5, 4), (6, 3), (7, 2), (8, 1), (9, 0)]
>>> c.sort(key=lambda x:x[0])
>>> c
[(0, 9), (1, 8), (2, 7), (3, 6), (4, 5), (5, 4), (6, 3), (7, 2), (8, 1), (9, 0)]
>>> c.sort(key=lambda x:x[1])
>>> c
[(9, 0), (8, 1), (7, 2), (6, 3), (5, 4), (4, 5), (3, 6), (2, 7), (1, 8), (0, 9)]