Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Sort products by price then name

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.

Requirements

  • Primary key: price.
  • Secondary key: name.
  • Do not drop products.

Constraints

  • products: a list of product records with price and name fields.
  • Equal prices must still have a stable, name-based order.

Examples

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

beginner

Sort products by price then name

Interview-style drill: Sort a list of product records by price ascending, breaking ties alphabetically.

Sort products by price, then by name for ties.