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])- A. 12 6 (2, 1, 3)
- B. 12 6 (2, 3, 1)
- C. 24 6 (2, 3, 1)
- 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
- What is printed? python def sqsorted(a): l, r = 0, len(a) - 1 out = [0] len(a) k = len(a) - 1 while l <= r: if abs(a[l]) > abs(a[r])…
- What is printed? python def minpath(g): dp = [0] len(g[0]) for i, row in enumerate(g): for j, v in enumerate(row): if i == 0 and j == 0…
- What is printed? python from functools import lrucache def wb(s, words): @lrucache(maxsize=None) def go(i): if i == len(s): return 1…
- What is printed? python from functools import cache @cache def ways(s, i=0): if i == len(s): return 1 if s[i] == '0': return 0 total =…
- What is printed? python import heapq words = ['bb', 'a', 'cc', 'dd', 'e'] print(heapq.nlargest(2, words, key=len), heapq.nsmallest(2…
- What is printed? python data = [3, 8, 15, 4, 22] res = [y for x in data if (y := x 2) > 20] print(res, y)