Courseiva
Computer Programming and Python FundamentalshardMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

A company is developing a data processing pipeline that must handle large datasets efficiently. They notice that using a list comprehension to filter data is slower than expected. Which alternative approach would likely improve performance?

⚠ Common exam trap

The PCEP exam often tests the misconception that map() or lambda functions are inherently faster for filtering, when in fact the key performance difference lies in lazy evaluation versus eager list construction, which is the core advantage of generator expressions.

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

Using a generator expression

Generator expressions produce items lazily, one at a time, without storing the entire filtered result in memory. This reduces memory overhead and can improve performance when processing large datasets, as the pipeline can iterate over generated items without building a full list first.

Answer analysis

Option-by-option breakdown

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

  • Using the map() function

    Why it's wrong here

    map() returns an iterator, but it still processes all elements; for filtering, a generator expression is more direct.

  • Using a for loop with append

    Why it's wrong here

    A for loop with append creates a list as well, so similar performance.

  • Using a generator expression

    Why this is correct

    Generators yield items one by one and avoid storing the entire list, reducing memory and often improving speed.

  • Using a lambda function

    Why it's wrong here

    Lambda is not an alternative to list comprehension; it's a way to create anonymous functions.

About these practice questions

One of 498 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 →

How Courseiva writes practice questions · Editorial policy

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.