350-401 · Question #1337
350-401 Question #1337: Real Exam Question with Answer & Explanation
The correct answer is A: for device in device_ip.items(): print(device). Explanation Option A is correct because .items() returns a view of key-value pairs as tuples, and by iterating with a single variable (device), each iteration captures the entire tuple (key, value) - which is exactly what print(device) then outputs. Option B is wrong because unpa
Question
Refer to the exhibit. The key value pairs must be extracted by iterating through a list of tuples. Which statement completes the snippet and prints each key value pair as a tuple?
Options
- Afor device in device_ip.items(): print(device)
- Bfor device, value in device_ip.items(): print(device)
- Cfor device in device_ip: print(device)
- Dfor device in device_ip.values(): print(device)
Explanation
Explanation
Option A is correct because .items() returns a view of key-value pairs as tuples, and by iterating with a single variable (device), each iteration captures the entire tuple (key, value) - which is exactly what print(device) then outputs.
Option B is wrong because unpacking into two variables (device, value) splits the tuple, so print(device) would only print the key, not the full key-value tuple pair.
Option C is wrong because iterating directly over a dictionary (without .items()) only yields the keys, not tuples containing both key and value.
Option D is wrong because .values() returns only the values of the dictionary, completely omitting the keys, so you'd never see the full key-value pair.
💡 Memory Tip: Think of it this way - if you want the whole tuple, use one variable with
.items(). If you want to split the tuple, use two variables. The question asks to print as a tuple, so keep it together withfor device in device_ip.items().
Topics
Community Discussion
No community discussion yet for this question.