ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
from itertools import zip_longest, product, combinations, permutations
print(list(zip_longest("ab", [1, 2, 3], fillvalue="-"))[-1], len(list(product("ab", repeat=3))), len(list(combinations(range(5), 2))), len(list(permutations("aab"))))- A. ('-', 3) 8 10 6
- B. ('-', 3) 6 10 3
- C. (None, 3) 8 10 6
- D. ('-', 3) 8 20 6
Correct answer: A. ('-', 3) 8 10 6
zip_longest pads the shorter input with fillvalue. product with repeat=3 gives 2^3 = 8 tuples, C(5,2) = 10, and permutations works on positions, not values, so 'aab' gives 3! = 6 (with duplicates).
More Python Programming questions
- What is printed? (Output lines are shown separated by " / ".) python from itertools import groupby data = [1, 1, 2, 1, 3, 3] print([(k…
- What is printed? python from functools import reduce print(reduce(lambda a, b: a 10 + b, [1, 2, 3]), reduce(lambda a, b: a + b, [], 7)…
- What is printed? python from functools import lrucache calls = 0 @lrucache(maxsize=2) def f(x): global calls calls += 1 return x for v in…
- What is printed? (Output lines are shown separated by " / ".) python from functools import partial def power(base, exp): return base exp…
- What is printed? python x = [3, 1, 2] y = sorted(x) z = reversed(x) x.append(0) print(y, list(z))
- What is printed? python m = map(lambda v: v 2, [1, 2, 3]) f = filter(None, [0, 1, 2]) print(list(m), list(m), next(f), list(zip(f, "xyz")))