ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import itertools
rows = [[1, 2], [3], [4, 5, 6]]
print(sum(len(r) for r in rows), list(itertools.chain(*rows))[-1], max(map(len, rows)))
  1. A. 6 4 3
  2. B. 6 6 2
  3. C. 5 6 3
  4. D. 6 6 3

Correct answer: D. 6 6 3

The three rows have 2, 1 and 3 items, which is 6 in total. chain flattens the rows, so the last item is 6. The longest row has 3 items.

More Python Programming questions

Exams that ask this topic