ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(list(zip([1, 2, 3], 'ab')), list(zip('ab', [1, 2, 3], [True])), len(list(zip())))
  1. A. [(1, 'a'), (2, 'b'), (3, None)] [('a', 1, True)] 0
  2. B. [(1, 'a'), (2, 'b')] [('a', 1, True), ('b', 2, None)] 0
  3. C. [(1, 'a'), (2, 'b')] [('a', 1, True)] 0
  4. D. [(1, 'a'), (2, 'b')] [('a', 1, True)] 1

Correct answer: C. [(1, 'a'), (2, 'b')] [('a', 1, True)] 0

zip stops at the shortest iterable, so the first result has two pairs and the second has one. zip with no arguments yields nothing, so its length is 0.

More Python Programming questions

Exams that ask this topic