ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from itertools import accumulate
print(list(accumulate([1, 2, 3], initial=0)), next(iter(sorted({3, 1, 2}))))- A. [1, 3, 6] 1
- B. [0, 1, 3, 6] 3
- C. [0, 1, 2, 3] 1
- D. [0, 1, 3, 6] 1
Correct answer: D. [0, 1, 3, 6] 1
accumulate with initial=0 yields the running sums starting from 0. sorted of the set gives a list whose first element is 1.
More Python Programming questions
- What is printed? python st = [] for t in '2 1 + 3 '.split(): if t.isdigit(): st.append(int(t)) else: b = st.pop() a = st.pop() st.append(a…
- What is printed? python a = [-2, 1, -3, 4, -1, 2, 1, -5, 4] best = cur = a[0] for x in a[1:]: cur = max(x, cur + x) best = max(best, cur)…
- What is printed? python print(sum(bin(i).count('1') for i in range(8)))
- What is printed? python seen = {} for i, x in enumerate([2, 7, 11, 15]): if 9 - x in seen: print((seen[9 - x], i)) break seen[x] = i
- What is printed? python print(len(bin(10 6)) - 2, len(bin(2 20)) - 2)
- What is printed? python print(max(range(10), key=lambda x: x % 4), min([], default=7))