python sort by 2 keys code example
Example 1: sort by multiple keys in object python
s = sorted(s, key = lambda x: (x[1], x[2]))
Example 2: python sort multiple keys
records.sort(
key = lambda l: (l[0], l[2])
)
Example 3: 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