ProgrammingVery hardIBM · Deloitte · Product Company SDE

What does the following Python 3 code print? import itertools print(list(itertools.chain.from_iterable([[1, 2], [3], [4, 5, 6]])))

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

Correct answer: B. [1, 2, 3, 4, 5, 6]

chain.from_iterable flattens one level of nesting, concatenating all inner iterables in order.

More Python Programming questions

Exams that ask this topic