Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A programmer needs to store configuration settings keyed by string, where each key maps to a list of allowed values. Which data structure is most appropriate?

⚠ Common exam trap

Python Institute often tests the distinction between data structures that store pairs (like dictionaries) versus those that store sequences (like lists or tuples), and the trap here is that candidates may choose a list of tuples (Option C) because it visually pairs keys and values, but overlook that it lacks the efficient key-based lookup that a dictionary provides.

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

✓

A dictionary where keys are strings and values are lists.

A dictionary in Python provides direct key-to-value mapping, making it ideal for storing configuration settings where each string key must map to a list of allowed values. Dictionaries offer O(1) average-time complexity for lookups, which is efficient for retrieving the list of values for a given key. This structure directly models the requirement without unnecessary nesting or indirection.

Answer analysis

Option-by-option breakdown

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

  • ✗

    A tuple of lists where each list starts with the key.

    Why it's wrong here

    A tuple of lists stores keys positionally, so retrieving a key's values requires scanning every element rather than direct lookup. Tuples suit fixed, ordered, immutable records; they cannot map arbitrary string keys to values, which a dictionary handles natively.

  • ✓

    A dictionary where keys are strings and values are lists.

    Why this is correct

    A dictionary maps each string key directly to its associated list, giving O(1) average lookup by key. This satisfies the stem's requirement for string-keyed configuration where each key holds multiple allowed values, since lists preserve the ordered collection of values per key without needing separate parallel structures.

  • ✗

    A list of tuples where each tuple contains a key and a list of values.

    Why it's wrong here

    A list of tuples requires linear scanning to find a key, giving O(n) lookup instead of a dictionary's direct hashing. Lists of tuples suit ordered sequences of fixed records; here the requirement is keyed retrieval of value lists, which a dictionary provides.

  • ✗

    A set of strings representing the keys, with a separate list for values.

    Why it's wrong here

    A set of keys plus a separate list of values gives no structural link between a key and its values, so lookups cannot reliably retrieve the correct list. Sets are for unordered uniqueness testing and membership checks, not key-to-value mapping; a dictionary is required here.

About these practice questions

One of 482 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.