A list of event dicts, a keyword, and you want every summary that mentions the keyword — case-insensitive. What does the if clause inside a list comprehension let you do?
Filter as you extract? So one comprehension both grabs the summary field and throws out any item whose summary doesn't contain the keyword?
Exactly. The expression before for shapes each output; the if after the loop decides who's in. Case-insensitive matching drops both sides to lower():
matches = [e.get("summary", "") for e in items
if keyword.lower() in e.get("summary", "").lower()]And the .lower() is the tiny but important trick — without it, "standup" and "Standup" wouldn't match?
Every in check is literal. Normalising both sides to lowercase is the standard case-insensitive pattern. Full function wraps the comprehension after the API call:
def event_titles_with_keyword(keyword: str) -> list:
result = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
items = result.get("items", [])
return [e.get("summary", "") for e in items
if keyword.lower() in e.get("summary", "").lower()]What if keyword is an empty string? Every event has "" inside its summary — would the function return every title?
Yes, empty-string in always returns True. If the caller sends "", they get every title. That's a feature if "show me all" is meaningful; an early return with an empty list is an equally reasonable design choice. Pick the contract that matches your callers.
So I could filter emails by subject, tasks by title, sheets by cell — the skeleton is the same no matter which list I'm filtering?
Filter, normalise, match. Swap the field name and the list source; the rest is identical. This is the shape that every real automation uses whenever keywords meet data.
TL;DR: if keyword.lower() in item.get(field, "").lower() handles case and missing-field in one expression.
e.get("summary", "").lower() on both sides of inin check is case-insensitive after normalisation| Match | Pattern |
|---|---|
| Exact | k == field |
| Substring | k in field |
| Case-insensitive substring | k.lower() in field.lower() |
Substring matching with case-folding is the default for human-typed keywords. Swap to regex only when you need anchors, groups, or whole-word boundaries.
A list of event dicts, a keyword, and you want every summary that mentions the keyword — case-insensitive. What does the if clause inside a list comprehension let you do?
Filter as you extract? So one comprehension both grabs the summary field and throws out any item whose summary doesn't contain the keyword?
Exactly. The expression before for shapes each output; the if after the loop decides who's in. Case-insensitive matching drops both sides to lower():
matches = [e.get("summary", "") for e in items
if keyword.lower() in e.get("summary", "").lower()]And the .lower() is the tiny but important trick — without it, "standup" and "Standup" wouldn't match?
Every in check is literal. Normalising both sides to lowercase is the standard case-insensitive pattern. Full function wraps the comprehension after the API call:
def event_titles_with_keyword(keyword: str) -> list:
result = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
items = result.get("items", [])
return [e.get("summary", "") for e in items
if keyword.lower() in e.get("summary", "").lower()]What if keyword is an empty string? Every event has "" inside its summary — would the function return every title?
Yes, empty-string in always returns True. If the caller sends "", they get every title. That's a feature if "show me all" is meaningful; an early return with an empty list is an equally reasonable design choice. Pick the contract that matches your callers.
So I could filter emails by subject, tasks by title, sheets by cell — the skeleton is the same no matter which list I'm filtering?
Filter, normalise, match. Swap the field name and the list source; the rest is identical. This is the shape that every real automation uses whenever keywords meet data.
TL;DR: if keyword.lower() in item.get(field, "").lower() handles case and missing-field in one expression.
e.get("summary", "").lower() on both sides of inin check is case-insensitive after normalisation| Match | Pattern |
|---|---|
| Exact | k == field |
| Substring | k in field |
| Case-insensitive substring | k.lower() in field.lower() |
Substring matching with case-folding is the default for human-typed keywords. Swap to regex only when you need anchors, groups, or whole-word boundaries.
Create a free account to get started. Paid plans unlock all tracks.