ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(list(enumerate('ab', start=1)), list(zip(reversed([1, 2, 3]), 'xyz')))
  1. A. [(0, 'a'), (1, 'b')] [(3, 'x'), (2, 'y'), (1, 'z')]
  2. B. [(1, 'a'), (2, 'b')] [(3, 'x'), (2, 'y'), (1, 'z')]
  3. C. [(1, 'a'), (2, 'b')] [(1, 'x'), (2, 'y'), (3, 'z')]
  4. D. [(1, 'a'), (2, 'b'), (3, None)] [(3, 'x'), (2, 'y'), (1, 'z')]

Correct answer: B. [(1, 'a'), (2, 'b')] [(3, 'x'), (2, 'y'), (1, 'z')]

enumerate with start=1 counts from 1, and reversed walks the list backwards before zip pairs it with the string. zip stops at the shorter input.

More Python Programming questions

Exams that ask this topic