PCEP Computer Programming and Python Fundamentals • Set 2
PCEP Computer Programming and Python Fundamentals Practice Test 2 — 15 questions with explanations. Free, no signup.
A junior developer is working on a script that processes user data. The script reads a CSV file into a list of dictionaries. Each dictionary represents a user with keys 'name', 'age', and 'email'. The developer needs to filter out users under 18 and store their names in a list. The current code is:
users = [{'name': 'Alice', 'age': 17, 'email': 'alice@example.com'}, {'name': 'Bob', 'age': 22, 'email': 'bob@example.com'}]
minors = []
for user in users:
if user['age'] < 18:minors.append(user['name'])
print(minors)The code works, but the senior developer says it is not idiomatic and suggests a more concise solution. Which of the following approaches is the best replacement?