ProgrammingHardInfosys · Python

What is printed?

What is printed?
m = map(lambda x: x * 2, [1, 2, 3])
print(list(m), list(m), sum(map(int, '123')))
  1. A. [2, 4, 6] [2, 4, 6] 6
  2. B. [2, 4, 6] [] 6
  3. C. [1, 2, 3] [] 6
  4. D. [2, 4, 6] [] 123

Correct answer: B. [2, 4, 6] [] 6

A map object is a one-shot iterator: the first list() exhausts it, so the second gives []. The sum of the digits 1, 2, 3 is 6.

More Python Programming questions

Exams that ask this topic