Sorting a list of objects by multiple attributes

gry at ll.mit.edu gry at ll.mit.edu
Mon Apr 10 21:29:23 EDT 2006


For multiple keys the form is quite analogous:

   L.sort(key=lambda i: (i.whatever, i.someother, i.anotherkey))

I.e., just return a tuple with the keys in order from your lambda.
Such tuples sort nicely.  

-- George Young




More information about the Python-list mailing list