ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(list(filter(lambda x: x > 0, map(lambda x: x - 2, [1, 2, 3, 4]))))
  1. A. [-1, 0, 1, 2]
  2. B. [1, 2]
  3. C. [1, 2, 3]
  4. D. [0, 1, 2]

Correct answer: B. [1, 2]

map subtracts 2 from each item, giving -1, 0, 1 and 2, and filter keeps the positive results, which are 1 and 2.

More Python Programming questions

Exams that ask this topic