ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
import itertools
print(list(itertools.combinations([1, 2, 3, 4], 2)))
  1. A. [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
  2. B. [(1, 2), (2, 1), (1, 3), (3, 1)]
  3. C. [(1, 2, 3, 4)]
  4. D. [(1, 2), (3, 4)]

Correct answer: A. [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]

combinations with r=2 gives every UNORDERED pair in lexicographic order of indices, without repeating an element paired with an earlier one: 4C2 = 6 pairs.

More Python Programming questions

Exams that ask this topic