Python data engineering interview problem. Difficulty: beginner. Pattern: Sorting. About 10 minutes. Part of the Pro drill bank.
A catalog export needs products listed by price, and by name when prices tie, so two $12 items do not swap order between runs.
Sort products by price, then by name for ties.
Input: sort_products([{'name': 'b', 'price': 2}, {'name': 'a', 'price': 2}, {'name': 'c', 'price': 1}]) Output: [{'name': 'c', 'price': 1}, {'name': 'a', 'price': 2}, {'name': 'b', 'price': 2}] This input follows the stated rules and produces this output.
Topics: lakebench, python, sorting.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Sort a list of product records by price ascending, breaking ties alphabetically.
Sort products by price, then by name for ties.