python 中 sort()函数所带的参数

it2022-05-05  137

>>> 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)]

转载于:https://www.cnblogs.com/hawkgogo001/archive/2011/11/16/2251204.html


最新回复(0)