Parse a JSON API Response
Medium
You are given a Python dictionary representing a JSON API response with a list of users under the key "users", where each user has "name" and "active" keys. Write a function active_user_names(data) that returns a list of names of users where active is True.
Input
A dict like {"users": [{"name": "Alice", "active": True}, {"name": "Bob", "active": False}]}
Output
A list of names of active users.
Example
Input
{"users": [{"name": "Alice", "active": True}, {"name": "Bob", "active": False}, {"name": "Carl", "active": True}]}
Output
['Alice', 'Carl']
Use a list comprehension iterating over data["users"], filtering where user["active"] is True, and extracting user["name"].
15 XP on solve
Back to lesson
Your Solution
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to submit your solution and earn XP.