lexicographic order
Ordering sequences the way a dictionary orders words: compare the first elements, and only if they are equal move on to the next.
In more detail
Python compares tuples lexicographically, so sorting by a key that returns (department, -salary) sorts by department and then by salary descending in one call. The same rule lets (priority, task) tuples order a heap by priority.
Related terms
- tuple — An ordered, fixed-length group of values in which each position can have its own meaning and type.
- key function — A function given as key= to sorted, sort, min or max, which turns each item into the value to compare by.
- priority queue — A collection where each item has a priority and the item removed next is always the one with the highest priority, not the oldest.
Taught in
- Sorting In Real Systems: Stability, Keys And External Sort — Algorithms & Data Structures for Working Engineers