ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(list(zip(*[(1, 'a'), (2, 'b')])))
  1. A. [(1, 'a'), (2, 'b')]
  2. B. [(1, 2), ('a', 'b')]
  3. C. [(1, 2), ('b', 'a')]
  4. D. [(1, 2)]

Correct answer: B. [(1, 2), ('a', 'b')]

zip(*pairs) transposes the list of pairs, so the first tuple collects the numbers and the second collects the letters.

More Python Programming questions

Exams that ask this topic