ProgrammingModerateCAT · MBA placement

What is printed?

What is printed?
from itertools import permutations
p = sorted(permutations('cab'))
print([''.join(x) for x in p][3], len(p))
  1. A. cab 6
  2. B. bac 6
  3. C. bca 5
  4. D. bca 6

Correct answer: D. bca 6

Sorted permutations run in lexicographic order: abc, acb, bac, bca, cab, cba. Index 3 is bca, and there are 6 permutations.

More Python Programming questions

Exams that ask this topic