python sort by 2 keys in different order code example
Example: 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