ProgrammingVery hardProduct Company SDE · Python internals

What does the following Python 3 code print? import itertools print(list(itertools.dropwhile(lambda x: x < 3, [1, 2, 3, 4, 1, 2])))

  1. A. [3, 4, 1, 2]
  2. B. [1, 2]
  3. C. [4, 1, 2]
  4. D. []

Correct answer: A. [3, 4, 1, 2]

dropwhile drops elements only while the predicate is true from the start, stopping permanently at the first failure (3); everything after, including later small values, is kept.

More Python Programming questions

Exams that ask this topic