Python practice: List Comprehensions & Inline Filtering
Chapter 10 · 8 questions · included in full access
Question 1 · easy
Basic list comprehension
Solve it in your browserGiven
prices = [100, 200, 300], createtaxed = [p * 1.18 for p in prices]using a list comprehension and printtaxed:Question 2 · easy
Filter large orders with if
Solve it in your browserGiven
orders = [450, 1200, 890, 2300, 310], filter orders >= 1000 using[o for o in orders if o >= 1000]. Printlarge:Question 3 · easy
Conditional label transformation
Solve it in your browserGiven
units = [12, 5, 20, 8], create labels:["Bulk" if u >= 10 else "Standard" for u in units]. Printlabels:Question 4 · easy
Clean string cities list
Solve it in your browserGiven
raw = [" pune ", "MUMBAI", " delhi "], normalize them using[c.strip().title() for c in raw]. Printclean:Question 5 · easy
Extract product name lengths
Solve it in your browserGiven
products = ["Desk", "Chair", "Monitor"], create a list of character lengths using[len(p) for p in products]. Printlengths:Question 6 · medium
Extract fields from list of dicts
Solve it in your browserGiven
deals = [{"rep": "Asha", "val": 1200}, {"rep": "Ravi", "val": 800}], extract rep names whereval >= 1000. Printreps:Question 7 · easy
Parse string numbers to integers
Solve it in your browserGiven
raw_nums = ["10", "25", "40", "15"], convert each string to anintusing comprehension and printint_nums:Question 8 · medium
Discounted prices list
Solve it in your browserGiven
prices = [500, 1200, 300, 2000], apply a 10% discount to items over 1000 (leaving others unchanged). Printfinal_prices:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing