ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
from itertools import accumulate, chain, islice, count
print(list(accumulate([1, 2, 3, 4])), list(chain("ab", [1])), list(islice(count(5, 2), 3)))- A. [1, 3, 6, 10] ['a', 'b', 1] [5, 7, 9]
- B. [1, 2, 3, 4] ['ab', 1] [5, 7, 9]
- C. [1, 3, 6, 10] ['a', 'b', 1] [5, 6, 7]
- D. [10] ['a', 'b', 1] [5, 7, 9]
Correct answer: A. [1, 3, 6, 10] ['a', 'b', 1] [5, 7, 9]
accumulate yields running totals, chain flattens one level (a string contributes its characters), and islice takes the first 3 values of the infinite count 5, 7, 9, ...
More Python Programming questions
- What is printed? python from itertools import ziplongest, product, combinations, permutations print(list(ziplongest("ab", [1, 2, 3]…
- 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))