Parsing nested API responses — without crashing on a missing key — step 9 of 9
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>
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>
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.