There is a class with two domains of value. I want sort a list of such pairs with following criteria:
- If the first domain are different, sort by first domain;
- Otherwise, sort by second domain.
It is easy to sort only by first domain with lambda:
list.sort(key=lambda x:x.first)
or
sorted(list, key=lambda x:x.first)
But if I want to further compare x.second, how can I write lambda the function?