Build a Price Lookup Dict

Easy ⏱ 8 min 72% acceptance ★★★★★ 4.8
Write to_catalog(pairs) that converts a list of (product, price) tuples into a dict mapping product → price, but excluding any product priced at 0 or below, using a dict comprehension.

Examples

Example 1
Input
to_catalog([('pen', 10), ('demo', 0), ('book', 250)])
Output
{'pen': 10, 'book': 250}
Explanation

demo is dropped because its price is not positive.

Constraints

  • Use a dict comprehension.
  • Keep only prices > 0.

Topics

List Comprehensionsdict comprehension

Companies

RazorpayPayPal

Hints

Hint 1

{k: v for k, v in pairs} is the base shape.

Hint 2

Add an if filter at the end.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.