PCEP Control Flow, Loops, Lists and Logic Practice Question
A logistics coordinator tracks delivery statuses in a list of strings. The coordinator wants to build a new list containing only the statuses that are not equal to `"delivered"`, preserving the original order. Which code fragment produces the desired list `pending`?
⚠ Common exam trap
The trap here is writing `not "delivered"` as if it compared a variable, when it actually negates a non-empty string literal.
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
✓
pending = [s for s in statuses if s != "delivered"]
Selecting all entries that differ from a target value calls for a comprehension whose condition compares each element with `!=`. That preserves order and includes every non-matching status. Inverting the comparison keeps the wrong subset, `remove` mutates and returns `None`, and testing the literal's truthiness yields nothing at all.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
pending = statuses.remove("delivered")
Why it's wrong here
`list.remove` mutates the original list in place and returns `None`, so `pending` would be assigned `None` and later use of it would fail. It also removes only the first matching occurrence, leaving any other `"delivered"` entries behind. This neither returns a list nor removes all matches, so it cannot produce the required result.
- ✗
pending = [s for s in statuses if not "delivered"]
Why it's wrong here
The condition `not "delivered"` evaluates the non-empty string literal, which is always truthy, so its negation is always `False`. The comprehension therefore yields an empty list every time. The code confuses testing a string for truthiness with comparing a value to a target, a subtle but decisive error.
- ✓
pending = [s for s in statuses if s != "delivered"]
Why this is correct
This list comprehension iterates every status, keeps only those whose value differs from `"delivered"`, and collects them in the original order. It is concise and equivalent to an explicit loop with a conditional append. Because the condition is evaluative rather than terminating, all non-delivered entries are retained regardless of position.
- ✗
pending = [s for s in statuses if s == "delivered"]
Why it's wrong here
The condition here keeps the delivered statuses and discards everything else, which is the exact opposite of what the coordinator needs. The resulting list would contain only completed deliveries, so downstream logic would treat unfinished shipments as done. The comparison operator must be `!=` to select the pending items.
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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 Python Institute exam blueprint
This PCEP practice question is part of Courseiva's free Python Institute 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 PCEP exam.