table = [ ['1', 'Du', 'GeovinDu', '13824350518',92], ['2', 'Rose', 'Tom', '1882458888',38], ['3', 'Lin', 'bo', '852000000',87], ['4', 'Ada', 'Jaing', '18999999999',87]] # Bubble Sort冒泡排序法 curr=0 tablesore=[] rowindex=4 for i in range(0,len(table)-1): #for j in range(0, len(table[0]) - i - 1): #print(table[i][j],table[i+1][j],table[i],table[i+1]) if table[i][rowindex] >table[i+1][rowindex]: temp = table[i] table[i] = table[i+1] table[i+1] = temp print(table) print('*********') table = [ ['1', 'Du', 'GeovinDu', '13824350518',92], ['2', 'Rose', 'Tom', '1882458888',38], ['3', 'Lin', 'bo', '852000000',87], ['4', 'Ada', 'Jaing', '18999999999',87]] table.sort(key=lambda row: (row[4],row[0] ), reverse=True) print(table) table.sort(key=lambda row: (row[4]), reverse=True) print(table) table.sort(key=lambda row: (row[4],row[0]), reverse=True) print(table) sorted(table, key=lambda x: x[4], reverse=True) print(table) # from https://scripteverything.com/python-2d-list-sort-by-multiple-columns-code-examples-no-imports-one-liners # from https://numpy.org/doc/stable/reference/generated/numpy.sort.html # from https://thispointer.com/sorting-2d-numpy-array-by-column-or-row-in-python/
标签:sort,python,print,table,True,87,row From: https://www.cnblogs.com/geovindu/p/18449009