Back to Lesson
Compound Ordering
Apply sorted logic using lambda parameters processing complex mapping arrays.
Instructions
- Embed dataset list:.
pairs = [("Alice", 95), ("Bob", 82), ("Carol", 95), ("Dave", 70)] - You want to sort first by the number (descending), and secondly by the name string (ascending).
- Utilize.
sorted(pairs, key=lambda x: (-x[1], x[0])) - Print the evaluated sequence array.
main.py
main.py
Ctrl + Enter