s = sorted(s, key = lambda x: (x[1], x[2]))
或者,你可以使用来实现相同的效果itemgetter
(速度更快,并且避免了Python函数调用):
import operator
s = sorted(s, key = operator.itemgetter(1, 2))
并请注意,你可以在此处使用sort
而不是使用sorted
,然后重新分配:
s.sort(key = operator.itemgetter(1, 2))
Python-按多个属性对列表进行排序?
s = sorted(s, key = lambda x: (x[1], x[2]))
或者,你可以使用来实现相同的效果itemgetter
(速度更快,并且避免了Python函数调用):
import operator
s = sorted(s, key = operator.itemgetter(1, 2))
并请注意,你可以在此处使用sort
而不是使用sorted
,然后重新分配:
s.sort(key = operator.itemgetter(1, 2))