Skip to content
C

First 5 Titles from a Post List

Mediumpython

Given a JSON array of posts (as text, simulating what response.json() would return from a posts API), print just the titles of the first 5.

Approach: json.loads() the array into a list of dicts, slice the first 5 with [:5], and print each one's title field.

Input: One line: a JSON array of post objects, each with a title field.

Output: The title of each of the first 5 posts, one per line (fewer if there are less than 5).

Input (stdin)

Output

Run your code to see output here...