ProgrammingHardInfosys HackWithInfy · TCS CodeVita

What does the following Python 3 code print? import itertools print(list(itertools.product([1, 2], [3, 4])))

  1. A. [(1, 3), (1, 4), (2, 3), (2, 4)]
  2. B. [(1, 2), (3, 4)]
  3. C. [(1, 3), (2, 4)]
  4. D. [(1, 3), (2, 3), (1, 4), (2, 4)]

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

product computes the Cartesian product; for each value from the first list it pairs with each value from the second, in order.

More Python Programming questions

Exams that ask this topic