Your make_update_line takes a stats dict. Sometimes you want just the three numbers — total MRR, total customers, avg ARPU — as a quick tuple. How would you handle 'all plans' vs a specific plan?
After make_update_line I have the formatted line. But if I want to compute those three values as a quick check — maybe just totals across all plans — I'd have to hardcode the plan name.
Default arguments solve exactly that. def summarize_plan(customers, plan='all') means calling with just customers gives you all plans; passing a plan name filters first. Two behaviours, one parameter:
def summarize_plan(customers: list, plan: str = "all") -> tuple:
if plan != "all":
customers = [c for c in customers if c.get("plan") == plan]
total_mrr = sum(c.get("mrr", 0) for c in customers)
total_count = len(customers)
avg_arpu = round(total_mrr / max(total_count, 1), 2)
return (round(total_mrr, 2), total_count, avg_arpu)What's a tuple? Is it different from a list?
A tuple is an immutable ordered sequence — written with parentheses: (14850.0, 99, 150.0). You can't append to it. a, b, c = summarize_plan(customers) unpacks all three values into separate variables in one line. That's tuple unpacking.
total_mrr, count, arpu = summarize_plan(customers, 'pro')
print(f"MRR: ${total_mrr:,.2f}, Count: {count}, ARPU: ${arpu:.2f}")So total_mrr, count, arpu = summarize_plan(customers, 'pro') — I get three clean variables back in one call.
One return, three variables. Python's most elegant shortcut. Spreadsheets would need three separate formulas or a helper row.
Default args mean I don't have to write a separate 'all-plans' version. One function, two modes. That's how real code scales.
Never use a mutable default — def f(items=[]) is a famous Python trap. The empty list is created once and reused across all calls. Use None and reassign: if items is None: items = [].
def f(x, y=10): # y defaults to 10 if not passed
return (x, y) # returns a tuple
a, b = f(5) # unpacks: a=5, b=10| Feature | Tuple | List |
|---|---|---|
| Syntax | (1, 2, 3) | [1, 2, 3] |
| Mutable | No | Yes |
| Use case | Fixed return values | Growing collections |
def f(items=[]) — mutable default trap. Use None and reassign inside the function.
Your make_update_line takes a stats dict. Sometimes you want just the three numbers — total MRR, total customers, avg ARPU — as a quick tuple. How would you handle 'all plans' vs a specific plan?
After make_update_line I have the formatted line. But if I want to compute those three values as a quick check — maybe just totals across all plans — I'd have to hardcode the plan name.
Default arguments solve exactly that. def summarize_plan(customers, plan='all') means calling with just customers gives you all plans; passing a plan name filters first. Two behaviours, one parameter:
def summarize_plan(customers: list, plan: str = "all") -> tuple:
if plan != "all":
customers = [c for c in customers if c.get("plan") == plan]
total_mrr = sum(c.get("mrr", 0) for c in customers)
total_count = len(customers)
avg_arpu = round(total_mrr / max(total_count, 1), 2)
return (round(total_mrr, 2), total_count, avg_arpu)What's a tuple? Is it different from a list?
A tuple is an immutable ordered sequence — written with parentheses: (14850.0, 99, 150.0). You can't append to it. a, b, c = summarize_plan(customers) unpacks all three values into separate variables in one line. That's tuple unpacking.
total_mrr, count, arpu = summarize_plan(customers, 'pro')
print(f"MRR: ${total_mrr:,.2f}, Count: {count}, ARPU: ${arpu:.2f}")So total_mrr, count, arpu = summarize_plan(customers, 'pro') — I get three clean variables back in one call.
One return, three variables. Python's most elegant shortcut. Spreadsheets would need three separate formulas or a helper row.
Default args mean I don't have to write a separate 'all-plans' version. One function, two modes. That's how real code scales.
Never use a mutable default — def f(items=[]) is a famous Python trap. The empty list is created once and reused across all calls. Use None and reassign: if items is None: items = [].
def f(x, y=10): # y defaults to 10 if not passed
return (x, y) # returns a tuple
a, b = f(5) # unpacks: a=5, b=10| Feature | Tuple | List |
|---|---|---|
| Syntax | (1, 2, 3) | [1, 2, 3] |
| Mutable | No | Yes |
| Use case | Fixed return values | Growing collections |
def f(items=[]) — mutable default trap. Use None and reassign inside the function.
Jordan wants a quick summary of a plan — total MRR, total customer count, and avg ARPU — as a tuple for fast unpacking. Write `summarize_plan(customers, plan='all')` that filters to the given plan (or uses all if plan='all') and returns `(total_mrr, total_count, avg_arpu)` as a tuple.
Tap each step for scaffolded hints.
No blank-editor panic.