PCEP Control Flow, Loops, Lists and Logic Practice Question
Which loop is more efficient for iterating over a large list when you only need the values, not indices?
⚠ Common exam trap
Python Institute often tests the misconception that `enumerate()` is always the best choice for iteration, but the trap here is that candidates overlook the specific requirement ('only the values, not indices') and choose a more general but less efficient option like B or A.
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
✓
for value in mylist:
Iterating directly over the list with `for value in mylist:` avoids the overhead of indexing or enumeration. This is the most efficient approach in Python for accessing only the values, as it uses the list's internal iterator, which is implemented in C and involves no function calls or index lookups per iteration.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
for i in range(len(mylist)): value = mylist[i]
Why it's wrong here
Indexing with range(len(...)) performs a lookup per element and creates an index sequence, adding overhead the direct iteration avoids. It is tempting when positions are genuinely needed, but here only values are required, so iterating the list directly is the correct approach.
- ✗
for i, value in enumerate(mylist):
Why it's wrong here
enumerate() yields an index-value tuple for every element, adding per-iteration unpacking overhead the stem does not need since indices are irrelevant. It is tempting because it is the standard idiom when both position and value are required, such as numbering output or updating by index.
- ✓
for value in mylist:
Why this is correct
Iterating directly with `for value in mylist` avoids index lookups and the overhead of `range()` and `len()` calls, yielding each element straight from the list's iterator. This satisfies the stem's efficiency constraint for large lists where indices are unnecessary, giving cleaner, faster traversal than index-based loops.
- ✗
for value in mylist[::-1]:
Why it's wrong here
Slicing with [::-1] builds a full reversed copy of the list before iteration begins, doubling memory use and adding an O(n) copy step on a large list. It is tempting because it reverses order, which suits descending traversal, but the stem requires only values, not reversal.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.