ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
m = map(lambda v: v * 2, [1, 2, 3])
f = filter(None, [0, 1, 2])
print(list(m), list(m), next(f), list(zip(f, "xyz")))
  1. A. [2, 4, 6] [2, 4, 6] 1 [(2, 'x')]
  2. B. [2, 4, 6] [] 0 [(1, 'x'), (2, 'y')]
  3. C. [2, 4, 6] [] 1 [(1, 'x'), (2, 'y')]
  4. D. [2, 4, 6] [] 1 [(2, 'x')]

Correct answer: D. [2, 4, 6] [] 1 [(2, 'x')]

map and filter return one-shot iterators: the second list(m) is empty. filter(None, ...) drops falsy 0, so next(f) is 1 and only 2 is left for zip.

More Python Programming questions

Exams that ask this topic