http and apis — making the call9 / 9
parsing nested api responses — without crashing on a missing key
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill of the chapter. Write a function
summarize_search(response) that takes a GitHub-shaped search
response and returns a list of strings, one per repo, in this format:
<name> (★<stars>) — <owner>
Walk the response defensively:
- If
itemsis missing or empty, return[]. - For each repo, default
nameto"<unnamed>",stargazers_countto0, and the owner'sloginto"<unknown>".
The starter has a response with two complete repos and one repo
missing its owner. Use the bottom loop as-is.
Expected output:
fastapi (★70000) — tiangolo
httpx (★12000) — encode
mystery-repo (★5) — <unknown>
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _