Python practice: List Comprehensions & Inline Filtering

Chapter 10 · 8 questions · included in full access

  1. Question 1 · easy

    Basic list comprehension

    Given prices = [100, 200, 300], create taxed = [p * 1.18 for p in prices] using a list comprehension and print taxed:

    Solve it in your browser
  2. Question 2 · easy

    Filter large orders with if

    Given orders = [450, 1200, 890, 2300, 310], filter orders >= 1000 using [o for o in orders if o >= 1000]. Print large:

    Solve it in your browser
  3. Question 3 · easy

    Conditional label transformation

    Given units = [12, 5, 20, 8], create labels: ["Bulk" if u >= 10 else "Standard" for u in units]. Print labels:

    Solve it in your browser
  4. Question 4 · easy

    Clean string cities list

    Given raw = [" pune ", "MUMBAI", " delhi "], normalize them using [c.strip().title() for c in raw]. Print clean:

    Solve it in your browser
  5. Question 5 · easy

    Extract product name lengths

    Given products = ["Desk", "Chair", "Monitor"], create a list of character lengths using [len(p) for p in products]. Print lengths:

    Solve it in your browser
  6. Question 6 · medium

    Extract fields from list of dicts

    Given deals = [{"rep": "Asha", "val": 1200}, {"rep": "Ravi", "val": 800}], extract rep names where val >= 1000. Print reps:

    Solve it in your browser
  7. Question 7 · easy

    Parse string numbers to integers

    Given raw_nums = ["10", "25", "40", "15"], convert each string to an int using comprehension and print int_nums:

    Solve it in your browser
  8. Question 8 · medium

    Discounted prices list

    Given prices = [500, 1200, 300, 2000], apply a 10% discount to items over 1000 (leaving others unchanged). Print final_prices:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing