200-901 Software Development and Design Practice Question
A developer is writing a Python function that accepts a list of interface names and returns a dictionary mapping each interface name to the number of characters in that name. The function should also verify that the input is a list and raise a TypeError otherwise. Which approach correctly implements the described behavior?
⚠ Common exam trap
The trap here is treating assert or ValueError as equivalent to raising TypeError, when the exception type and runtime behavior differ.
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
✓
def map_lengths(names): if not isinstance(names, list): raise TypeError('names must be a list') return {n: len(n) for n in names}
The requirement is twofold: validate that the argument is a list and raise TypeError when it is not, then return a dictionary of name to length. Only the implementation using isinstance with a TypeError raise and a dictionary comprehension satisfies both constraints in a single, correct function.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
def map_lengths(names): if type(names) != list: raise ValueError('names must be a list') return {n: n.__len__() for n in names}
Why it's wrong here
This performs an exact type comparison and raises ValueError rather than TypeError. It also breaks for list subclasses that should be accepted, and the required exception type is wrong, so it does not meet the requirement even though the resulting dictionary would be equivalent for a plain list.
- ✗
def map_lengths(names): assert isinstance(names, list) return dict(zip(names, map(len, names)))
Why it's wrong here
Using assert raises AssertionError, not TypeError, and assertions can be stripped when Python runs with optimization enabled. Although the dictionary construction is valid, the required exception type and reliable validation are not provided, so this approach fails the stated contract.
- ✗
def map_lengths(names): return {n: len(n) for n in names}
Why it's wrong here
This returns the correct dictionary of interface name to length, but it performs no type validation. If a caller passes a string or tuple, the function silently produces a result instead of raising TypeError, so it does not satisfy the requirement to verify that the input is a list.
- ✓
def map_lengths(names): if not isinstance(names, list): raise TypeError('names must be a list') return {n: len(n) for n in names}
Why this is correct
This implementation checks the input with isinstance against list and raises TypeError when the check fails, then builds the required dictionary with a comprehension. It satisfies both stated requirements: type validation that raises TypeError and a mapping of each interface name to its character length.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 200-901 question from scratch — 975 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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Cisco exam blueprint
This 200-901 practice question is part of Courseiva's free Cisco 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 200-901 exam.