Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A Python developer is validating a list of sensor readings stored in `readings`. The developer needs to build a new list containing only readings that are strictly greater than 10. Which two code fragments correctly produce a list of only the values greater than 10? (Choose two.)

⚠ Common exam trap

The trap here is mixing up strict and inclusive comparison operators and assuming lists expose a `filter()` method, when filtering is done with a comprehension or the built-in `filter()` function.

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

✓

filtered = [r for r in readings if r > 10]

A list comprehension with a trailing `if r > 10` and the built-in `filter()` with a lambda both select exactly the elements satisfying the strict comparison, producing the required list. The other fragments either use an inclusive comparison that wrongly keeps 10, call a nonexistent list method, or use invalid comprehension syntax with an `else` clause in the filter position.

Answer analysis

Option-by-option breakdown

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

  • ✗

    filtered = [r for r in readings if r > 10 else r]

    Why it's wrong here

    A list comprehension filter clause cannot contain an `else` branch; the `if` after the `for` is a filter and must be a plain condition. This syntax raises a SyntaxError. The ternary `else` form belongs before the `for` keyword when used for value selection, not after it as a filter.

  • ✓

    filtered = [r for r in readings if r > 10]

    Why this is correct

    This list comprehension iterates over every element in `readings`, evaluates the condition `r > 10`, and includes only those elements for which the condition is true. The result is a new list preserving the original order of qualifying readings, which is exactly the filtered output the developer needs for sensor validation.

  • ✓

    filtered = list(filter(lambda r: r > 10, readings))

    Why this is correct

    `filter()` applies the lambda predicate to each element and keeps those for which it returns true, and wrapping the result in `list()` materializes the iterator into a concrete list. The predicate `r > 10` matches the strict comparison requirement, so this fragment produces the same filtered list as the comprehension approach.

  • ✗

    filtered = [r for r in readings if r >= 10]

    Why it's wrong here

    The condition `r >= 10` uses a greater-than-or-equal comparison, so a reading of exactly 10 would be included. The requirement states strictly greater than 10, meaning 10 itself must be excluded. This fragment therefore produces an incorrect list containing borderline values that should have been filtered out.

  • ✗

    filtered = readings.filter(r > 10)

    Why it's wrong here

    Lists do not have a `.filter()` method in Python; that method exists on some other objects but not on built-in lists. Calling `readings.filter(...)` raises an AttributeError at runtime. The built-in `filter()` function must be called as `filter(predicate, iterable)` and then converted to a list if a list result is desired.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

Courseiva writes every PCEP question from scratch — 482 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 →

How Courseiva writes practice questions · Editorial policy

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.