Dsa
Sorting
Easy
Product Price Sorter
You are managing an inventory of products represented as a list of dictionaries containing product names and their prices. Your task is to sort the products by price in ascending order. If two products have the same price, sort them alphabetically by their names. The input will contain an integer N followed by N lines, each containing a product's name and its price. The output should print the sorted list of products.
Input Format:
N
name1 price1
name2 price2
...
nameN priceN
Output Format:
name1 price1
name2 price2
...
nameN priceN
Example:
Input:
3
Widget 10.99
Gadget 10.99
Doodad 5.75
Output:
Doodad 5.75
Gadget 10.99
Widget 10.99
Key concepts
sortingdictionariestuples
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now