Lesson 151 of 1570
Python Lists and Dicts With AI
Lists hold ordered items. Dicts hold keyed pairs. Comprehensions make both sing. Learn the core patterns AI will push you toward.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1Two Collections Run the World
- 2list
- 3dict
- 4comprehension
Concept cluster
Terms to connect while reading
Section 1
Two Collections Run the World
Most Python code is a pile of lists and dicts. If you can walk them, filter them, and transform them, you can read 80 percent of any codebase.
Comprehensions, sorted with a key, and .get() with a default — the workhorse trio.
users = [
{"name": "Ada", "active": True, "score": 91},
{"name": "Bo", "active": False, "score": 72},
{"name": "Cy", "active": True, "score": 85},
]
# Active users, sorted by score descending
active = sorted(
(u for u in users if u["active"]),
key=lambda u: u["score"],
reverse=True,
)
# Lookup table by name
by_name: dict[str, dict] = {u["name"]: u for u in users}
print(by_name.get("Ada", {}).get("score")) # 91Ask AI to write comprehensions for you
Counter is a dict subclass built for this exact pattern. AI loves to suggest it.
# Prompt: "Given list of dicts with 'tag' and 'count', return a dict mapping tag -> total count."
from collections import Counter
def totals(items: list[dict]) -> dict[str, int]:
c: Counter[str] = Counter()
for item in items:
c[item["tag"]] += item["count"]
return dict(c)Key terms in this lesson
The big idea: lists and dicts plus a few standard-library helpers cover most data work. Ask AI for the idiomatic form, then keep it readable.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Python Lists and Dicts With AI”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 30 min
Python Lists & Dicts — The Two Collections You Can't Live Without
Lists are ordered rows; dicts are labeled lookups. You'll use both to solve a real problem, and catch the mistakes autocomplete makes.
Builders · 25 min
What Does AI-Assisted Coding Even Mean?
AI-assisted coding is not magic and not cheating. It is a new way of working where a model drafts, you decide. Let's draw a map before we start building.
Builders · 30 min
Your First Copilot-Style Completion
Let's actually feel what autocomplete is like. Write a comment, pause, and watch a full function appear. Then learn what to do next.
