ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(list(map(lambda x, y: x * y, [1, 2, 3], [4, 5])))
  1. A. [4, 10, 0]
  2. B. [4, 10, 3]
  3. C. [4, 5, 10]
  4. D. [4, 10]

Correct answer: D. [4, 10]

map with several iterables stops at the shortest one, just as zip does. The pairs are (1, 4) and (2, 5), so the result has two items.

More Python Programming questions

Exams that ask this topic