What is the output of the following Python code? print(list(zip(“ab”, )))
Correct answer B. [('a', 1), ('b', 2)]
Explanation
By default zip() stops as soon as the shortest input is exhausted, so the extra 3 is silently ignored and no padding with None happens. To pad shorter inputs use itertools.zip_longest, and to raise an error on unequal lengths pass strict=True, available since Python 3.10.
Answer checked How we write and check questions
Discussion