ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import itertools
print(sum(a < b for a, b in itertools.pairwise([1, 3, 2, 5, 4, 6])))
  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 2

Correct answer: C. 3

pairwise yields the five consecutive pairs (1,3), (3,2), (2,5), (5,4), (4,6). Of these, the pairs with an increase are (1,3), (2,5) and (4,6), so the sum of True values is 3.

More Python Programming questions

Exams that ask this topic