ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
m = [[1, 2, 3], [4, 5, 6]]
t = list(zip(*m))
print(t, [list(r) for r in zip(*t)] == m, [x for row in m for x in row][::-2])
  1. A. [(1, 2, 3), (4, 5, 6)] True [6, 4, 2]
  2. B. [(1, 4), (2, 5), (3, 6)] False [6, 4, 2]
  3. C. [(1, 4), (2, 5), (3, 6)] True [5, 3, 1]
  4. D. [(1, 4), (2, 5), (3, 6)] True [6, 4, 2]

Correct answer: D. [(1, 4), (2, 5), (3, 6)] True [6, 4, 2]

zip(*m) transposes the matrix into tuples; transposing twice gives back the rows (as lists after conversion). Flattening gives [1..6], and [::-2] takes 6, 4, 2.

More Python Programming questions

Exams that ask this topic