200-901 Software Development and Design Practice Question
A developer wants to process a list of server hostnames and create a new list containing only hostnames that start with 'web'. Which Python list comprehension correctly accomplishes this?
⚠ Common exam trap
200-901 often tests the placement of the `if` clause in list comprehensions—candidates may mistakenly put the condition before the `for` (as in a conditional expression) or use `in` instead of `startswith`.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
[hostname for hostname in servers if hostname.startswith('web')]
The correct list comprehension is `[hostname for hostname in servers if hostname.startswith('web')]`. It iterates over `servers`, applies the condition `hostname.startswith('web')` as a filter, and includes only those hostnames in the new list. This matches the requirement to create a new list of hostnames starting with 'web'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
[hostname.startswith('web') for hostname in servers]
Why it's wrong here
This expression evaluates startswith('web') for every hostname, producing a list of booleans rather than the hostnames themselves, so no filtering occurs. It is tempting because startswith is exactly the correct predicate for the 'starts with web' requirement, and it would be right if the goal were to test each hostname and return True or False results.
- ✗
[hostname for hostname in servers if 'web' in hostname]
Why it's wrong here
Testing 'web' in hostname matches the substring anywhere, so hostnames such as 'myweb01' or 'proxyweb' pass, violating the requirement that names start with 'web'. It is tempting because the membership test with in is valid, readable Python, and it would be correct if the requirement were to find hostnames containing 'web' in any position.
- ✓
[hostname for hostname in servers if hostname.startswith('web')]
Why this is correct
The comprehension filters with `hostname.startswith('web')`, returning only matching elements while preserving the original list's order. The `if` clause sits after the iteration expression, so each hostname is tested before inclusion — satisfying the stem's requirement to produce a new list containing solely hostnames beginning with 'web'.
- ✗
[hostname if hostname.startswith('web') for hostname in servers]
Why it's wrong here
Placing the conditional before the for clause is a syntax error; list comprehensions require the if filter after the iteration. It is tempting because it reads like an English sentence and uses the correct startswith('web') predicate, and it would be right if rewritten with the filter positioned after the for clause.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 200-901 question from scratch — 975 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Cisco exam blueprint
This 200-901 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 200-901 exam.