In-Stock Product Names

Easy ⏱ 8 min 85% acceptance ★★★★★ 4.9
Each product is a dict like {'name': 'Pen', 'stock': 4}. Write in_stock_names(products) returning the names of products whose stock is greater than zero, in order, with one comprehension.

Examples

Example 1
Input
in_stock_names([{'name': 'Pen', 'stock': 4}, {'name': 'Ink', 'stock': 0}])
Output
['Pen']
Explanation

Ink has zero stock.

Constraints

  • Return names only.
  • Single comprehension.

Topics

List Comprehensionslist of dicts

Companies

FlipkartWalmartSwiggy

Hints

Hint 1

Filter on p['stock'] > 0.

Hint 2

Map to p['name'].

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