The CFO just forwarded a spreadsheet — 40 campaigns, every channel, all Q2 spend. She wants one thing: which campaigns are burning more than $5,000. In Excel, you'd slap an AutoFilter on the spend column. In Python, where do you even put 40 rows?
In a table, I guess — but we've only stored one thing per variable so far. is_over_budget compared two floats. That won't scale to 40 campaigns.
Right. One variable, one value — that's a named cell. A list is the whole column. campaigns = [{"name": "Email", "spend": 1250.0}, {"name": "Paid Search", "spend": 8700.0}] is your campaign table, 40 rows, in one name. Index in with campaigns[0] for the first row, campaigns[-1] for the last. len(campaigns) is your row count. And "Email" in [c["name"] for c in campaigns] checks membership — same idea as COUNTIF > 0:
campaigns = [
{"name": "Email", "spend": 1250.0},
{"name": "Paid Search", "spend": 8700.0},
{"name": "Display", "spend": 450.0}
]
print(campaigns[0]) # {"name": "Email", "spend": 1250.0}
print(len(campaigns)) # 3
print(campaigns[-1]["name"]) # DisplayThe in for membership — that feels backwards. I'm asking if something is in the list, but I have to build a whole list comprehension just to check a field? That seems clunky.
Fair pushback — that instinct is right. For a field buried inside a list of dicts you need the extra step, but membership check isn't the real tool here anyway. The loop is. Start with result = [], walk each campaign, compare spend to the threshold using the same > logic from is_over_budget, and append the matches. One condition, one list built up row by row.
So it's literally clicking through 40 rows and highlighting the ones above $5,000 — except Python does it before I can blink.
Before you can save the file. Here's the full function:
def filter_high_spend(campaigns: list, threshold: float) -> list:
result = []
for c in campaigns:
if c["spend"] > threshold:
result.append(c)
print(f"Found {len(result)} campaigns above ${threshold:,.2f}")
return resultresult = [] is my blank filter column, the loop is the AutoFilter, and append is checking the box. That's exactly how I think about it in the spreadsheet.
That mental model will carry you through every collection problem this week. The pattern — empty result, loop, conditional check, append — is the scaffold. The condition changes: maybe it's channel instead of spend, maybe it's CPL instead of a flat threshold. The structure stays the same.
A list holds ordered items in one name. Key operations:
| Operation | Syntax | What it does |
|---|---|---|
| Create | items = [] | Empty list |
| Append | items.append(x) | Add to end |
| Index | items[0] / items[-1] | First / last |
| Length | len(items) | Row count |
| Membership | x in items | True if present |
result = []
for item in collection:
if condition:
result.append(item)
return result
This replaces an Excel AutoFilter. The condition uses the same > comparison as is_over_budget — now applied to every row in the list.
The CFO just forwarded a spreadsheet — 40 campaigns, every channel, all Q2 spend. She wants one thing: which campaigns are burning more than $5,000. In Excel, you'd slap an AutoFilter on the spend column. In Python, where do you even put 40 rows?
In a table, I guess — but we've only stored one thing per variable so far. is_over_budget compared two floats. That won't scale to 40 campaigns.
Right. One variable, one value — that's a named cell. A list is the whole column. campaigns = [{"name": "Email", "spend": 1250.0}, {"name": "Paid Search", "spend": 8700.0}] is your campaign table, 40 rows, in one name. Index in with campaigns[0] for the first row, campaigns[-1] for the last. len(campaigns) is your row count. And "Email" in [c["name"] for c in campaigns] checks membership — same idea as COUNTIF > 0:
campaigns = [
{"name": "Email", "spend": 1250.0},
{"name": "Paid Search", "spend": 8700.0},
{"name": "Display", "spend": 450.0}
]
print(campaigns[0]) # {"name": "Email", "spend": 1250.0}
print(len(campaigns)) # 3
print(campaigns[-1]["name"]) # DisplayThe in for membership — that feels backwards. I'm asking if something is in the list, but I have to build a whole list comprehension just to check a field? That seems clunky.
Fair pushback — that instinct is right. For a field buried inside a list of dicts you need the extra step, but membership check isn't the real tool here anyway. The loop is. Start with result = [], walk each campaign, compare spend to the threshold using the same > logic from is_over_budget, and append the matches. One condition, one list built up row by row.
So it's literally clicking through 40 rows and highlighting the ones above $5,000 — except Python does it before I can blink.
Before you can save the file. Here's the full function:
def filter_high_spend(campaigns: list, threshold: float) -> list:
result = []
for c in campaigns:
if c["spend"] > threshold:
result.append(c)
print(f"Found {len(result)} campaigns above ${threshold:,.2f}")
return resultresult = [] is my blank filter column, the loop is the AutoFilter, and append is checking the box. That's exactly how I think about it in the spreadsheet.
That mental model will carry you through every collection problem this week. The pattern — empty result, loop, conditional check, append — is the scaffold. The condition changes: maybe it's channel instead of spend, maybe it's CPL instead of a flat threshold. The structure stays the same.
A list holds ordered items in one name. Key operations:
| Operation | Syntax | What it does |
|---|---|---|
| Create | items = [] | Empty list |
| Append | items.append(x) | Add to end |
| Index | items[0] / items[-1] | First / last |
| Length | len(items) | Row count |
| Membership | x in items | True if present |
result = []
for item in collection:
if condition:
result.append(item)
return result
This replaces an Excel AutoFilter. The condition uses the same > comparison as is_over_budget — now applied to every row in the list.
Taylor's CFO needs a fast view of Q2 overspend: pull every campaign where spend exceeds a given threshold so the finance review can focus only on the high-cost campaigns. Write `filter_high_spend(campaigns, threshold)` that takes a list of campaign dicts (each with a `"spend"` key) and a float threshold, and returns a new list containing only the campaigns where `spend` is strictly greater than the threshold.
Tap each step for scaffolded hints.
No blank-editor panic.