Your Google Tasks list is a stack of to-do items — each with a title. How would you pull just the titles into a Python list?
Same pattern as searching emails? Call the list action, grab items, then a list comprehension to pull the title off each?
Exactly. GOOGLETASKS_LIST_TASKS returns {"items": [...]} where each item has a title field. A one-liner gets you the list of strings:
result = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {})
titles = [t.get("title", "") for t in result.get("items", [])]The comprehension does two things at once — iterate the items and extract a field. Is that idiomatic Python?
The most idiomatic shape for a simple transform. You read it left-to-right: "title for each task in items." That is the whole function once you wrap it:
def list_task_titles() -> list:
result = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {})
return [t.get("title", "") for t in result.get("items", [])]Why .get("title", "") and not t["title"] — do task titles ever go missing?
A task can exist with an empty title in some clients. Defaulting to "" keeps the type of the list stable — always strings, never None mixed in. Callers can filter empties out later with a simple comprehension if they need to.
So this one function gives me a clean list of my open tasks — I can print it, count it, feed it into the next pipeline step?
That is the whole point of a read function: return something plain enough that everything else downstream stays easy.
TL;DR: A list comprehension turns a list of dicts into a list of the field you care about.
Action.GOOGLETASKS_LIST_TASKS{} (lists the default task list){"items": [{"title": ..., "status": ...}, ...]}| Shape | When |
|---|---|
[t.get("title") for t in items] | pulling one field out |
for-loop with append | multi-line logic per item or side effects |
Your Google Tasks list is a stack of to-do items — each with a title. How would you pull just the titles into a Python list?
Same pattern as searching emails? Call the list action, grab items, then a list comprehension to pull the title off each?
Exactly. GOOGLETASKS_LIST_TASKS returns {"items": [...]} where each item has a title field. A one-liner gets you the list of strings:
result = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {})
titles = [t.get("title", "") for t in result.get("items", [])]The comprehension does two things at once — iterate the items and extract a field. Is that idiomatic Python?
The most idiomatic shape for a simple transform. You read it left-to-right: "title for each task in items." That is the whole function once you wrap it:
def list_task_titles() -> list:
result = toolset.execute_action(Action.GOOGLETASKS_LIST_TASKS, {})
return [t.get("title", "") for t in result.get("items", [])]Why .get("title", "") and not t["title"] — do task titles ever go missing?
A task can exist with an empty title in some clients. Defaulting to "" keeps the type of the list stable — always strings, never None mixed in. Callers can filter empties out later with a simple comprehension if they need to.
So this one function gives me a clean list of my open tasks — I can print it, count it, feed it into the next pipeline step?
That is the whole point of a read function: return something plain enough that everything else downstream stays easy.
TL;DR: A list comprehension turns a list of dicts into a list of the field you care about.
Action.GOOGLETASKS_LIST_TASKS{} (lists the default task list){"items": [{"title": ..., "status": ...}, ...]}| Shape | When |
|---|---|
[t.get("title") for t in items] | pulling one field out |
for-loop with append | multi-line logic per item or side effects |
Create a free account to get started. Paid plans unlock all tracks.