Sorting a list of lists in Python
问题 c2=[] row1=[1,22,53] row2=[14,25,46] row3=[7,8,9] c2.append(row2) c2.append(row1) c2.append(row3) c2 is now: [[14, 25, 46], [1, 22, 53], [7, 8, 9]] how do i sort c2 in such a way that for example: for row in c2: sort on row[2] the result would be: [[7,8,9],[14,25,46],[1,22,53]] the other question is how do i first sort by row[2] and within that set by row[1] 回答1: The key argument to sort specifies a function of one argument that is used to extract a comparison key from each list element. So