依据第二列排序
#!/usr/bin/python def takesecond(elem): return elem[1] random = [(3,2,2), (3,4,1), (4,1,0), (1, 3,-1),(5,7,89),(5,2,0),(2,100,90),(2,100,2),(2,100,1),(2,100,0),(2,100,90)] #ready=sorted(random,key=lambda x:(x[1],x[0])) ready=sorted(random,key=lambda x: (x[0], x[1],x[2]),reverse=False) print ready
依据第一列第二列第三列排序,都是升序:
#!/usr/bin/python a=[[1,2,3,4],[4,2,3,4],[1,3,9,2],[1,3,6,7],[4,2,9,1000],[4,2,0,100000],[9,2,0,4]] new=sorted(a, key = lambda x:(x[0],x[1],x[2])) for i in new: print i