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))- A. cab 6
- B. bac 6
- C. bca 5
- 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
- What is printed? python print(() is (), [] is [], (1, 2) == (1, 2))
- A program must answer 10^5 range-sum queries over an array of 10^5 numbers in CPython. Which approach is fastest?
- What is printed? python from functools import lrucache class C: @lrucache(maxsize=None) def f(self, x): return x 2 a, b = C(), C() a.f(1)…
- What is printed? python class A: def init(self, v): self.v = v def eq(self, o): return isinstance(o, A) and self.v == o.v xs = [A(1)…
- What is printed? python a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b)
- What is printed? python nums = [10, 9, 100, 1] print(sorted(nums, key=str), max(nums, key=str), sorted(map(str, nums))[-1])