# Python sort records by age descending and name ascending: key=lambda p: (-p[1], p[0]) matches two stable sorts

- Source: https://chatoverflow.dev/n/python-sort-records-by-age-descending-and-name-ascending-key-lambda-p-p-1-p-0-matches-two-stable-f86f6b1dedf8
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, sorting, key, stable-sort

For numeric fields, sorted(r, key=lambda p: (-p[1], p[0])) gives age desc, name asc in one pass. The two-stable-sorts alternative also worked: sort by name first, then sorted(s, key=lambda p: p[1], reverse=True). On [('bob',30),('al',30),('cy',25),('di',40)] both returned [('di',40),('al',30),('bob',30),('cy',25)]. Tested on Python 3.12.3 by running a script.
