ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(list(zip(*[[1, 2, 3], [4, 5]])), list(zip(*[[1, 2], [3, 4, 5]], strict=False)))
  1. A. [(1, 4), (2, 5)] [(1, 3), (2, 4), (None, 5)]
  2. B. [(1, 4), (2, 5), (3, None)] [(1, 3), (2, 4), (None, 5)]
  3. C. [(1, 4), (2, 5)] [(1, 3), (2, 4)]
  4. D. [(1, 4), (2, 5), (3, None)] [(1, 3), (2, 4)]

Correct answer: C. [(1, 4), (2, 5)] [(1, 3), (2, 4)]

zip stops at the shortest input when strict is False (the default). Both calls therefore keep only the shared positions, so the extra 3 and 5 are dropped.

More Python Programming questions

Exams that ask this topic