Courseiva
Software Development and DesignmediumMultiple SelectObjective-mapped

200-901 Dictionary iteration Practice Question

A Python script needs to iterate over a dictionary of network interfaces and print each interface name and its IP address. The dictionary is structured as: {'GigabitEthernet1/0/1': '10.1.1.1', 'GigabitEthernet1/0/2': None}. Which THREE code snippets correctly iterate and print the key-value pairs, skipping entries with None? (Choose three.)

⚠ Common exam trap

Candidates often confuse truthiness checks (if ip) with explicit None checks (if ip is not None). The truthiness check works for None but also for other falsy values, which may cause unintended skips. Additionally, print formatting differences (comma vs. concatenation vs. f-string) can lead to incorrect output spacing.

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

for iface, ip in interfaces.items(): if ip != None: print(f'{iface}: {ip}')

Options A, B, and D correctly iterate over the dictionary, skip entries where the IP is None, and print the key-value pairs. Option E uses truthiness to skip None, but that would also skip other falsy values like an empty string, and the print with commas adds spaces around the colon, making the output format inconsistent. Option C does not skip None and prints the value as the string 'None'.

Answer analysis

Option-by-option breakdown

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

  • for iface, ip in interfaces.items(): if ip != None: print(f'{iface}: {ip}')

    Why this is correct

    Correct: Uses .items() for key-value pairs, explicitly checks 'ip != None', and formats with f-string.

  • for iface, ip in interfaces.items(): if ip: print(f'{iface}: {ip}')

    Why this is correct

    Correct: Also uses .items() and truthiness check (if ip) to skip None, though it would also skip other falsy values. The f-string formatting is correct.

  • for iface in interfaces.keys(): print(iface + ': ' + interfaces.get(iface))

    Why it's wrong here

    Incorrect: Does not skip None, so prints 'None' as a string for entries with None IP.

  • for iface in interfaces: ip = interfaces[iface] if ip is not None: print(iface + ': ' + ip)

    Why this is correct

    Correct: Iterates over keys, retrieves value via indexing, uses explicit 'is not None' check, and concatenates strings for output.

  • for iface in interfaces: if interfaces[iface]: print(iface, ':', interfaces[iface])

    Why it's wrong here

    Incorrect: Uses truthiness check which could skip non-None falsy values, and print with commas produces spaces around the colon (e.g., 'iface : ip'), deviating from expected format.

About these practice questions

One of 989 original 200-901 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 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.