To sort two lists in parallel, what\'s the way of sorting by one list first, then for elements with the same value, sorting by the second list? Either list could have duplic
Pair, sort, unpair, write back:
list_a[:], list_b[:] = zip(*sorted(zip(list_a, list_b), key=lambda p: (-p[0], p[1])))
Writing back keeps it short and sorts the existing list objects rather than having separate new ones.
More vertical version, probably nicer:
pairs = list(zip(list_a, list_b))
pairs.sort(key=lambda p: (-p[0], p[1]))
list_a[:], list_b[:] = zip(*pairs)