python sorted by multiple keys code example
Example 1: python sort based on multiple keys
>>> def multisort(xs, specs):
... for key, reverse in reversed(specs):
... xs.sort(key=attrgetter(key), reverse=reverse)
... return xs
Example 2: python sort two key
s = sorted(s, key = lambda x: (x[1], x[2]))