You have two lists of dicts — Gmail messages and Calendar items — each with different shapes. You want one flat list of strings that mixes both. What Python technique takes two separate list comprehensions and hands back a single list?
+ between two lists? So I build a list of snippets, build a list of summaries, concatenate — one plus one equals a merged list?
Exactly. List concatenation is the simplest merge. Each source gets its own comprehension with the right key — snippet for Gmail, summary for Calendar — then + joins them:
snips = [m.get("snippet", "") for m in emails.get("messages", [])]
sums = [e.get("summary", "") for e in events.get("items", [])]Each dict has a different field name. Is there a way to remember which key each API uses for its text content?
Once per API, then it sticks. Gmail's preview is snippet; Calendar's label is summary. The comprehension structure is identical — only the field name changes. Full function:
def combined_snippets(max_emails: int, max_events: int) -> list:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_emails})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
snips = [m.get("snippet", "") for m in emails.get("messages", [])]
sums = [e.get("summary", "") for e in events.get("items", [])]
return snips + sumsThe returned list is a mix of email previews and event titles — is there a way to know which is which once they're merged?
Not from the string alone. If the caller needs the source label, prefix each string at extraction time: f"email: {m.get('snippet', '')}" and f"event: {e.get('summary', '')}". Keep this function simple — return raw strings; let the caller tag if they want.
So the shape is always the same — two reads, two comprehensions, one concatenation — and I can swap APIs without touching the structure?
One shape, two sources, one list. The next multi-source extract you write uses the same outline with different keys. That's the whole track in one function.
TL;DR: Each API gets its own comprehension, + stitches the two lists together.
m.get("snippet", "")e.get("summary", "")snips + sums returns a flat list of strings| API | Text field |
|---|---|
| Gmail | snippet |
| Calendar | summary |
| Tasks | title |
The comprehension skeleton stays identical — only the field name and the container key change when you swap APIs. Same muscle memory, different data.
You have two lists of dicts — Gmail messages and Calendar items — each with different shapes. You want one flat list of strings that mixes both. What Python technique takes two separate list comprehensions and hands back a single list?
+ between two lists? So I build a list of snippets, build a list of summaries, concatenate — one plus one equals a merged list?
Exactly. List concatenation is the simplest merge. Each source gets its own comprehension with the right key — snippet for Gmail, summary for Calendar — then + joins them:
snips = [m.get("snippet", "") for m in emails.get("messages", [])]
sums = [e.get("summary", "") for e in events.get("items", [])]Each dict has a different field name. Is there a way to remember which key each API uses for its text content?
Once per API, then it sticks. Gmail's preview is snippet; Calendar's label is summary. The comprehension structure is identical — only the field name changes. Full function:
def combined_snippets(max_emails: int, max_events: int) -> list:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_emails})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
snips = [m.get("snippet", "") for m in emails.get("messages", [])]
sums = [e.get("summary", "") for e in events.get("items", [])]
return snips + sumsThe returned list is a mix of email previews and event titles — is there a way to know which is which once they're merged?
Not from the string alone. If the caller needs the source label, prefix each string at extraction time: f"email: {m.get('snippet', '')}" and f"event: {e.get('summary', '')}". Keep this function simple — return raw strings; let the caller tag if they want.
So the shape is always the same — two reads, two comprehensions, one concatenation — and I can swap APIs without touching the structure?
One shape, two sources, one list. The next multi-source extract you write uses the same outline with different keys. That's the whole track in one function.
TL;DR: Each API gets its own comprehension, + stitches the two lists together.
m.get("snippet", "")e.get("summary", "")snips + sums returns a flat list of strings| API | Text field |
|---|---|
| Gmail | snippet |
| Calendar | summary |
| Tasks | title |
The comprehension skeleton stays identical — only the field name and the container key change when you swap APIs. Same muscle memory, different data.
Create a free account to get started. Paid plans unlock all tracks.