PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
Exhibit
Refer to the exhibit.
def process(data):
return {item: len(item) for item in data}
print(process(['apple', 'banana', 'cherry']))What is the output of the code in the exhibit?
⚠ Common exam trap
The PCEP exam often tests the distinction between `dict()` with a list of tuples versus other dictionary creation methods, and the trap here is that candidates mistakenly think the tuples are reversed or that keys are auto-generated as indices.
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
✓
{'apple':5, 'banana':6, 'cherry':6}
The code creates a dictionary using the `dict()` constructor with a list of tuples. Each tuple is a key-value pair. The keys are strings ('apple', 'banana', 'cherry') and the values are integers (5, 6, 6). The resulting dictionary is {'apple':5, 'banana':6, 'cherry':6}.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
{5:'apple', 6:'banana', 6:'cherry'}
Why it's wrong here
Swapped keys and values.
- ✗
{'apple':5, 'banana':7, 'cherry':6}
Why it's wrong here
Banana length is 6, not 7.
- ✗
{0:'apple', 1:'banana', 2:'cherry'}
Why it's wrong here
Uses index instead of length.
- ✓
{'apple':5, 'banana':6, 'cherry':6}
Why this is correct
Correct mapping of items to their lengths.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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 →
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.