Three sources, three key names, one flat list. Email snippets from Gmail, event summaries from Calendar, task titles from Tasks — all strings, all combined into a single list the caller can scan with one loop. Why not return three separate lists?
Because downstream code wants to search or sort across everything at once, without branching on source type?
Exactly. A flat list is the simplest structure that supports one search pass, one sort pass, one print loop. The key detail — each API uses a different field name for the text:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": 5})
snippets = [m.get("snippet", "") for m in emails.get("messages", [])]So the pattern is list_key then text_key per API — messages/snippet, items/summary, items/title?
Yes. Three comprehensions, one per API, then concatenate with +. Here's the full function:
def collect_all_titles(max_emails: int, max_events: int, max_tasks: int) -> list:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_emails})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
tasks = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {"max_results": max_tasks})
snippets = [m.get("snippet", "") for m in emails.get("messages", [])]
summaries = [e.get("summary", "") for e in events.get("items", [])]
titles = [t.get("title", "") for t in tasks.get("items", [])]
combined = snippets + summaries + titles
print(f"Collected {len(combined)} items across 3 sources")
return combinedIf any source returns nothing, the comprehension produces an empty list and [] + other is just other — no special case needed.
Correct. Concatenation handles zero-length inputs gracefully. That's what lets the function stay one clean line of assembly at the end.
So I see the real text from my inbox, my calendar, and my tasks all joined up — one list, three sources, everything live?
Three APIs, one shape, one pass to build it. Every downstream transform this month operates on a list like this one.
TL;DR: Three comprehensions, one concatenation — a list that downstream code treats uniformly.
snippet, Calendar: summary, Tasks: titlemessages, Calendar: items, Tasks: itemsa + b + c creates a new flat list in source order| API | List key | Text field |
|---|---|---|
| Gmail | messages | snippet |
| Calendar | items | summary |
| Tasks | items | title |
Three sources, three key names, one flat list. Email snippets from Gmail, event summaries from Calendar, task titles from Tasks — all strings, all combined into a single list the caller can scan with one loop. Why not return three separate lists?
Because downstream code wants to search or sort across everything at once, without branching on source type?
Exactly. A flat list is the simplest structure that supports one search pass, one sort pass, one print loop. The key detail — each API uses a different field name for the text:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": 5})
snippets = [m.get("snippet", "") for m in emails.get("messages", [])]So the pattern is list_key then text_key per API — messages/snippet, items/summary, items/title?
Yes. Three comprehensions, one per API, then concatenate with +. Here's the full function:
def collect_all_titles(max_emails: int, max_events: int, max_tasks: int) -> list:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_emails})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
tasks = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {"max_results": max_tasks})
snippets = [m.get("snippet", "") for m in emails.get("messages", [])]
summaries = [e.get("summary", "") for e in events.get("items", [])]
titles = [t.get("title", "") for t in tasks.get("items", [])]
combined = snippets + summaries + titles
print(f"Collected {len(combined)} items across 3 sources")
return combinedIf any source returns nothing, the comprehension produces an empty list and [] + other is just other — no special case needed.
Correct. Concatenation handles zero-length inputs gracefully. That's what lets the function stay one clean line of assembly at the end.
So I see the real text from my inbox, my calendar, and my tasks all joined up — one list, three sources, everything live?
Three APIs, one shape, one pass to build it. Every downstream transform this month operates on a list like this one.
TL;DR: Three comprehensions, one concatenation — a list that downstream code treats uniformly.
snippet, Calendar: summary, Tasks: titlemessages, Calendar: items, Tasks: itemsa + b + c creates a new flat list in source order| API | List key | Text field |
|---|---|---|
| Gmail | messages | snippet |
| Calendar | items | summary |
| Tasks | items | title |
Create a free account to get started. Paid plans unlock all tracks.