Which code correctly creates a dictionary pairing each name with their score, ignoring extra names?
hard
A. dict(zip(names, scores))
B. {names[i]: scores[i] for i in range(len(names))}
C. dict(zip(scores, names))
D. dict(zip(names + scores))
Solution
Step 1: Understand zip behavior with unequal lengths
zip stops at the shortest list length, so extra names are ignored.
Step 2: Check dictionary creation
Using dict(zip(names, scores)) pairs names with scores correctly.
Step 3: Analyze other options
{names[i]: scores[i] for i in range(len(names))} causes IndexError (longer names list). dict(zip(scores, names)) reverses keys and values. dict(zip(names + scores)) is invalid syntax.
Final Answer:
dict(zip(names, scores)) -> Option A
Quick Check:
zip stops at shortest list, dict pairs correctly [OK]
Hint: Use dict(zip(keys, values)) to pair lists safely [OK]