On this page
article
Custom Sort Key
Sort objects by attribute.
Category: basics
Problem
Sort objects by attribute.
Solution
sorted(users, key=lambda u: u['score'], reverse=True)
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path