Last week you flagged individual churned customers with is_churned. Now imagine your cap table has 500 rows. How do you filter to only the active ones above $100 MRR?
In Excel I'd add a filter, set status = active, set MRR > 100, and copy the result to a new sheet. That's about four clicks and a lot of manual checking.
In Python, a list is your cap table — ordered rows, each a customer dict. You iterate it, check conditions, and append the ones that pass to a results list. The whole pattern is five lines:
results = []
for customer in customers:
if customer["status"] == "active" and customer["mrr"] > min_mrr:
results.append(customer)What if a customer dict is missing the mrr key? Does customer["mrr"] crash?
Good instinct — it raises KeyError. Use .get("mrr", 0) to default to 0 for missing keys. That's the same .get() pattern you'll use whenever parsing API responses. Here's the full function:
def filter_active_customers(customers: list, min_mrr: float) -> list:
results = []
for customer in customers:
if customer.get("status") == "active" and customer.get("mrr", 0) > min_mrr:
results.append(customer)
print(f"Filtered to {len(results)} active customers")
return resultsSo instead of a four-click Excel filter, I call one function and get a clean Python list I can pass to the next step.
And the Excel filter doesn't compose. Your Python list does — you can sort it, group it, or pass it straight into categorize_customer from Day 7.
I just replaced my Monday Stripe export filter with a reusable function. My Excel tab just became optional.
Use .get() on every customer dict access from now on. API data and CSV imports always have missing keys — .get(key, default) is your safety net.
A list holds ordered items. You build a filtered list by iterating and appending.
results = []
for item in source:
if condition:
results.append(item)| Operation | Effect |
|---|---|
items[0] | First item |
items[-1] | Last item |
len(items) | Count |
items.append(x) | Add to end |
x in items | Membership check |
customer["mrr"] crashes on a missing key. customer.get("mrr", 0) defaults safely.
Last week you flagged individual churned customers with is_churned. Now imagine your cap table has 500 rows. How do you filter to only the active ones above $100 MRR?
In Excel I'd add a filter, set status = active, set MRR > 100, and copy the result to a new sheet. That's about four clicks and a lot of manual checking.
In Python, a list is your cap table — ordered rows, each a customer dict. You iterate it, check conditions, and append the ones that pass to a results list. The whole pattern is five lines:
results = []
for customer in customers:
if customer["status"] == "active" and customer["mrr"] > min_mrr:
results.append(customer)What if a customer dict is missing the mrr key? Does customer["mrr"] crash?
Good instinct — it raises KeyError. Use .get("mrr", 0) to default to 0 for missing keys. That's the same .get() pattern you'll use whenever parsing API responses. Here's the full function:
def filter_active_customers(customers: list, min_mrr: float) -> list:
results = []
for customer in customers:
if customer.get("status") == "active" and customer.get("mrr", 0) > min_mrr:
results.append(customer)
print(f"Filtered to {len(results)} active customers")
return resultsSo instead of a four-click Excel filter, I call one function and get a clean Python list I can pass to the next step.
And the Excel filter doesn't compose. Your Python list does — you can sort it, group it, or pass it straight into categorize_customer from Day 7.
I just replaced my Monday Stripe export filter with a reusable function. My Excel tab just became optional.
Use .get() on every customer dict access from now on. API data and CSV imports always have missing keys — .get(key, default) is your safety net.
A list holds ordered items. You build a filtered list by iterating and appending.
results = []
for item in source:
if condition:
results.append(item)| Operation | Effect |
|---|---|
items[0] | First item |
items[-1] | Last item |
len(items) | Count |
items.append(x) | Add to end |
x in items | Membership check |
customer["mrr"] crashes on a missing key. customer.get("mrr", 0) defaults safely.
Leila has 500 customers in her Stripe export and needs only the active ones above a minimum MRR threshold for her weekly investor update. Write `filter_active_customers(customers, min_mrr)` that returns a list of customer dicts where status is 'active' and mrr exceeds min_mrr — for example, given customers with mrr 150.0 and 30.0, `filter_active_customers(customers, 100.0)` should return only the one with mrr 150.0.
Tap each step for scaffolded hints.
No blank-editor panic.