Question 397 of 510
Computer Programming and Python FundamentalshardMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

This PCEP practice question tests your understanding of computer programming and python fundamentals. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

You are a developer in a financial firm. Your team is building a Python module that performs complex calculations on large datasets. To improve performance, you are using list comprehensions and built-in functions. Your code passes all unit tests, but during integration testing, the memory usage spikes unexpectedly. The problematic area is a function that constructs a large list of intermediate results using a list comprehension that references a generator. The code is:

def process(data):

results = [expensive_transform(x) for x in data]

# further processing on results

You suspect that the list comprehension stores all results in memory at once, but you need to keep the function's output as a list for subsequent operations. What is the best solution to reduce memory without changing the function's return type?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "best"

    Why it matters: Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

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

Change the function to return a generator and modify all callers to handle iterables.

Option A is correct: the generator expression creates items on the fly, but then list() consumes it to produce a list, still holding all in memory. So no improvement. Option B is correct: a loop with list.append is memory-equivalent to a list comprehension. Option C is correct: changing to a generator only postpones the problem because later operations require a list. Option D is the correct approach: lazily produce results using a generator, and only convert to list at the very end if necessary. If the subsequent processing can also work with an iterator, you can avoid the list entirely. The best solution is to change the whole processing pipeline to use iterators, not just one part.

Key principle: OSPF neighbour adjacency depends on matching area, hello/dead timers, network type, and authentication — IP reachability alone is not enough.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Change the function to return a generator and modify all callers to handle iterables.

    Why this is correct

    Avoids building the full list if subsequent processing can consume lazily.

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    OSPF neighbours must agree on key parameters.

  • Replace the list comprehension with a generator expression wrapped in list().

    Why it's wrong here

    This still forces immediate evaluation into a list.

  • Use a for loop with the .append() method instead of comprehension.

    Why it's wrong here

    Same memory consumption as comprehension.

  • Increase the system's available memory via configuration.

    Why it's wrong here

    Not a programming solution; does not address the root cause.

Common exam traps

Common exam trap: OSPF can fail even when IP connectivity looks correct

OSPF neighbour formation depends on matching areas, timers, network type, authentication and passive-interface behaviour. Do not choose an answer only because the devices can ping.

Detailed technical explanation

How to think about this question

OSPF questions usually test the details that control adjacency and route selection. Read the neighbour state, area, router ID and interface configuration before deciding what is wrong.

KKey Concepts to Remember

  • OSPF neighbours must agree on key parameters.
  • Router ID selection can affect neighbour relationships and LSDB output.
  • OSPF cost influences the preferred path.
  • A route can appear in OSPF information but not become the installed route.

TExam Day Tips

  • Check area mismatch first when OSPF adjacency fails.
  • Review passive interfaces when a network is advertised but no neighbour forms.
  • Use show ip ospf neighbor and show ip route clues carefully.

Key takeaway

OSPF neighbour adjacency depends on matching area, hello/dead timers, network type, and authentication — IP reachability alone is not enough.

Real-world example

How this comes up in practice

A practitioner preparing for the PCEP exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. OSPF neighbour adjacency depends on matching area, hello/dead timers, network type, and authentication — IP reachability alone is not enough. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Review OSPF neighbour requirements — matching area type, hello and dead timers, network type, stub flags, and authentication. Study show ip ospf neighbor states (INIT, 2-WAY, FULL). Then practise related PCEP OSPF questions on adjacency and route selection.

Related practice questions

Related PCEP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCEP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCEP question test?

Computer Programming and Python Fundamentals — This question tests Computer Programming and Python Fundamentals — OSPF neighbours must agree on key parameters..

What is the correct answer to this question?

The correct answer is: Change the function to return a generator and modify all callers to handle iterables. — Option A is correct: the generator expression creates items on the fly, but then list() consumes it to produce a list, still holding all in memory. So no improvement. Option B is correct: a loop with list.append is memory-equivalent to a list comprehension. Option C is correct: changing to a generator only postpones the problem because later operations require a list. Option D is the correct approach: lazily produce results using a generator, and only convert to list at the very end if necessary. If the subsequent processing can also work with an iterator, you can avoid the list entirely. The best solution is to change the whole processing pipeline to use iterators, not just one part.

What should I do if I get this PCEP question wrong?

Review OSPF neighbour requirements — matching area type, hello and dead timers, network type, stub flags, and authentication. Study show ip ospf neighbor states (INIT, 2-WAY, FULL). Then practise related PCEP OSPF questions on adjacency and route selection.

Are there clue words in this question I should notice?

Yes — watch for: "best". Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

What is the key concept behind this question?

OSPF neighbours must agree on key parameters.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 24, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.