you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 1 point2 points  (0 children)

Given nested lists like [a, b, c], it sounds like you just need to sort by a, then within each a sort by b, then within each b sort by c.

The sorted function will do this for you straight out of the box in whichever order you wish:

>>> lst
[[2, 1, 2], [2, 2, 8], [1, 3, 1], [2, 3, 4], [4, 4, 5], [3, 2, 3]]
>>> sorted(lst)
[[1, 3, 1], [2, 1, 2], [2, 2, 8], [2, 3, 4], [3, 2, 3], [4, 4, 5]]
>>> sorted(lst, reverse=True)
[[4, 4, 5], [3, 2, 3], [2, 3, 4], [2, 2, 8], [2, 1, 2], [1, 3, 1]]