Sort a list of tuplas

[ permalink ] [ download ]
# sort by first element
# if the are equal, compare second element of the tuplas (as integers)
# if seconds elements are equal, compare second element of the tuplas (as integers)

results = ( ('a',1,3), ('j',6,7), ('b',4,5), ('g',3,2), ('c',6,9) )

results.sort( lambda x,y: cmp( str(x[0]), str(y[0]) ) or cmp(int(y[1]),int(x[1])) or cmp( int(y[2]), int(x[2])) )
hits counter