What is the result of list(zip([1, 2, 3], ['a', 'b']))?
A
[1, 'a', 2, 'b', 3]
B
An error because the lengths differ
C
[(1, 'a'), (2, 'b')]
Correct answer
D
[(1, 'a'), (2, 'b'), (3, None)]
Correct answer
C. [(1, 'a'), (2, 'b')]
16 views
⚔️
Challenge a friend on Python
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
zip stops at the shortest input . Use itertools.zip_longest to pad missing values, or zip(..., strict=True) in Python 3.10+ to raise an error on unequal lengths.
Reference
Asked in: NTS, Python Developer Interviews
Doubts & discussionNot sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ What does enumerate(['a', 'b'], start=1) yield? Next MCQ › Why use copy.deepcopy() instead of copy.copy() for a list of lists?