Python
All Top 50 Python & Pandas Interview Questions#3
Multi-Key Sorting with Lambda Functions in Python
EasyInterview Question #3
Given a list of client dicts with `name`, `tier` (1 to 3, where 1 is highest), and `revenue`, sort the clients primarily by `tier` ascending, and secondarily by `revenue` descending.
Input Table: clients
3 rows preview| name | tier | revenue |
|---|---|---|
| Acme Corp | 1 | 50000 |
| Beta LLC | 2 | 80000 |
| Gamma Inc | 1 | 95000 |
Expected Output Structure3 rows
| name | tier | revenue |
|---|---|---|
| Gamma Inc | 1 | 95000 |
| Acme Corp | 1 | 50000 |
| Beta LLC | 2 | 80000 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Click "Run & Test" to execute your Pandas code against the test assertions.