You now have group_by_plan that buckets customers by plan. How does your board deck show the plan breakdown — total MRR, total seats, average ARPU per plan?
I build that from the pivot table manually. I sum the MRR column, sum the seats column, divide for ARPU. It's a separate tab in the spreadsheet. Three nested formulas per row.
That nested tab is now a nested dict in Python. You call group_by_plan to get the buckets, then iterate .items() to compute totals for each plan:
for plan, customers in groups.items():
total_mrr = sum(c.get("mrr", 0) for c in customers)
total_seats = sum(c.get("seats", 1) for c in customers)sum(c.get("mrr", 0) for c in customers) — is that a loop inside a function call?
Exactly — it's a generator expression. (expr for item in iterable) produces values on the fly; sum() consumes them. No intermediate list needed. Here's the full function:
def plan_summary(customers: list) -> dict:
groups = group_by_plan(customers)
summary = {}
for plan, group in groups.items():
total_mrr = sum(c.get("mrr", 0) for c in group)
total_seats = sum(c.get("seats", 1) for c in group)
avg_arpu = round(total_mrr / max(total_seats, 1), 2)
summary[plan] = {"total_mrr": round(total_mrr, 2), "total_seats": total_seats, "avg_arpu": avg_arpu}
print(f"Summary for {len(summary)} plans")
return summarySo plan_summary replaces my entire spreadsheet pivot tab. One function call, nested dict output, ready to pipe into the investor email.
Your spreadsheet pivot tab has been unemployed since Day 13. This is its formal notice.
I just built a full plan summary with totals and averages from a flat customer list. In Week 1 I was formatting one number. Now I'm aggregating a hundred.
sum() with a generator is idiomatic Python. Avoid building a temporary list just to sum it — sum(expr for x in items) is more memory-efficient and reads cleanly.
A dict of lists is the standard shape for grouped data in Python.
{"pro": [{...}, {...}], "starter": [{...}]}| Pattern | Use case |
|---|---|
for k, v in d.items() | Iterate key-value pairs |
sum(x for x in items) | Sum without intermediate list |
round(value, 2) | Round to 2 decimal places |
sum([]) returns 0 — safe on empty lists. total / count crashes when count == 0. Use max(count, 1) as the denominator.
You now have group_by_plan that buckets customers by plan. How does your board deck show the plan breakdown — total MRR, total seats, average ARPU per plan?
I build that from the pivot table manually. I sum the MRR column, sum the seats column, divide for ARPU. It's a separate tab in the spreadsheet. Three nested formulas per row.
That nested tab is now a nested dict in Python. You call group_by_plan to get the buckets, then iterate .items() to compute totals for each plan:
for plan, customers in groups.items():
total_mrr = sum(c.get("mrr", 0) for c in customers)
total_seats = sum(c.get("seats", 1) for c in customers)sum(c.get("mrr", 0) for c in customers) — is that a loop inside a function call?
Exactly — it's a generator expression. (expr for item in iterable) produces values on the fly; sum() consumes them. No intermediate list needed. Here's the full function:
def plan_summary(customers: list) -> dict:
groups = group_by_plan(customers)
summary = {}
for plan, group in groups.items():
total_mrr = sum(c.get("mrr", 0) for c in group)
total_seats = sum(c.get("seats", 1) for c in group)
avg_arpu = round(total_mrr / max(total_seats, 1), 2)
summary[plan] = {"total_mrr": round(total_mrr, 2), "total_seats": total_seats, "avg_arpu": avg_arpu}
print(f"Summary for {len(summary)} plans")
return summarySo plan_summary replaces my entire spreadsheet pivot tab. One function call, nested dict output, ready to pipe into the investor email.
Your spreadsheet pivot tab has been unemployed since Day 13. This is its formal notice.
I just built a full plan summary with totals and averages from a flat customer list. In Week 1 I was formatting one number. Now I'm aggregating a hundred.
sum() with a generator is idiomatic Python. Avoid building a temporary list just to sum it — sum(expr for x in items) is more memory-efficient and reads cleanly.
A dict of lists is the standard shape for grouped data in Python.
{"pro": [{...}, {...}], "starter": [{...}]}| Pattern | Use case |
|---|---|
for k, v in d.items() | Iterate key-value pairs |
sum(x for x in items) | Sum without intermediate list |
round(value, 2) | Round to 2 decimal places |
sum([]) returns 0 — safe on empty lists. total / count crashes when count == 0. Use max(count, 1) as the denominator.
You need a full plan breakdown for your board deck — total MRR, total seats, and average ARPU per plan — derived from a flat customer list. Write `plan_summary(customers)` that calls `group_by_plan` internally and returns a dict like `{'pro': {'total_mrr': 248.0, 'total_seats': 2, 'avg_arpu': 124.0}}` for each plan.
Tap each step for scaffolded hints.
No blank-editor panic.