ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
from itertools import permutations, combinations
print(len(list(permutations('abcd', 2))), len(list(combinations('abcd', 2))), list(permutations([1, 2, 3]))[3])
  1. A. 12 6 (2, 1, 3)
  2. B. 12 6 (2, 3, 1)
  3. C. 24 6 (2, 3, 1)
  4. D. 12 4 (2, 3, 1)

Correct answer: B. 12 6 (2, 3, 1)

Ordered pairs from 4 items give 12 permutations, and unordered pairs give 6 combinations. Permutations come out in positional lexicographic order, so index 3 is (2, 3, 1).

More Python Programming questions

Exams that ask this topic