ProgrammingHardTCS NQT · Wipro pattern

What is printed?

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

Correct answer: B. [4, 10]

map with several iterables stops at the shortest one, so the third element of the first list is ignored. The products are 1 x 4 and 2 x 5.

More Python Programming questions

Exams that ask this topic