You have a flat list of titles from three APIs. Now filter it — return only the items containing a keyword, case-insensitive. What's the filter expression?
A comprehension with an if clause? [x for x in items if keyword in x]?
Exactly. Plus .lower() on both sides for case-insensitive matching. And since the keyword never changes inside the loop, compute kw = keyword.lower() once outside — clean and avoids redundant work:
kw = keyword.lower()
matches = [x for x in combined if kw in x.lower()]So the work splits cleanly: first assemble the flat list, then filter it. Two concerns, two steps.
Exactly. One helper shape you will re-use everywhere. Here's the full function wrapping the three reads and the filter:
def filter_by_keyword(keyword: str, max_items: int) -> list:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_items})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
tasks = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {"max_results": max_items})
combined = (
[m.get("snippet", "") for m in emails.get("messages", [])]
+ [e.get("summary", "") for e in events.get("items", [])]
+ [t.get("title", "") for t in tasks.get("items", [])]
)
kw = keyword.lower()
matches = [x for x in combined if kw in x.lower()]
print(f"Filtered {len(matches)} items matching '{keyword}' from {len(combined)}")
return matchesWhat if the keyword has mixed case like 'Meeting' — does the caller need to lowercase it themselves?
No. keyword.lower() runs inside the function, so 'Meeting', 'meeting', and 'MEETING' all produce the same result. Case normalization belongs inside the filter, not in the caller.
So one call filters my live inbox, calendar, and tasks in a single pass — three sources, one keyword, one answer?
Three live APIs, one combined list, one filter comprehension. That is the Week 1 shape at full strength.
TL;DR: Assemble a flat list from three APIs, then apply one case-insensitive filter comprehension.
kw = keyword.lower() outside the loop[x for x in combined if kw in x.lower()]| Placement | Cost |
|---|---|
keyword.lower() inside the if | runs on every item |
kw = keyword.lower() above | runs once total |
You have a flat list of titles from three APIs. Now filter it — return only the items containing a keyword, case-insensitive. What's the filter expression?
A comprehension with an if clause? [x for x in items if keyword in x]?
Exactly. Plus .lower() on both sides for case-insensitive matching. And since the keyword never changes inside the loop, compute kw = keyword.lower() once outside — clean and avoids redundant work:
kw = keyword.lower()
matches = [x for x in combined if kw in x.lower()]So the work splits cleanly: first assemble the flat list, then filter it. Two concerns, two steps.
Exactly. One helper shape you will re-use everywhere. Here's the full function wrapping the three reads and the filter:
def filter_by_keyword(keyword: str, max_items: int) -> list:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_items})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
tasks = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {"max_results": max_items})
combined = (
[m.get("snippet", "") for m in emails.get("messages", [])]
+ [e.get("summary", "") for e in events.get("items", [])]
+ [t.get("title", "") for t in tasks.get("items", [])]
)
kw = keyword.lower()
matches = [x for x in combined if kw in x.lower()]
print(f"Filtered {len(matches)} items matching '{keyword}' from {len(combined)}")
return matchesWhat if the keyword has mixed case like 'Meeting' — does the caller need to lowercase it themselves?
No. keyword.lower() runs inside the function, so 'Meeting', 'meeting', and 'MEETING' all produce the same result. Case normalization belongs inside the filter, not in the caller.
So one call filters my live inbox, calendar, and tasks in a single pass — three sources, one keyword, one answer?
Three live APIs, one combined list, one filter comprehension. That is the Week 1 shape at full strength.
TL;DR: Assemble a flat list from three APIs, then apply one case-insensitive filter comprehension.
kw = keyword.lower() outside the loop[x for x in combined if kw in x.lower()]| Placement | Cost |
|---|---|
keyword.lower() inside the if | runs on every item |
kw = keyword.lower() above | runs once total |
Create a free account to get started. Paid plans unlock all tracks.