ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from itertools import accumulate print(list(accumulate([2, 3, 4], lambda a, b: a * b)), list(accumulate([1, -1, 2])))
- A. [2, 6, 24] [1, -1, 2]
- B. [2, 5, 9] [1, 0, 2]
- C. [2, 6, 24] [1, 0, 1]
- D. [2, 6, 24] [1, 0, 2]
Correct answer: D. [2, 6, 24] [1, 0, 2]
accumulate applies the function to the running value and the next item. The product path is 2, 6, 24, and the running sum of [1, -1, 2] is 1, 0, 2.
More Python Programming questions
- What is printed? python a = [[1, 2], [3, 4]] b = [row[:] for row in a] c = a[:] a[0][0] = 9 c[1][1] = 7 print(b, c)
- What is printed? python print(len(str(2 64)), (2 64).bitlength(), 2 64 % 9, pow(2, 64, 9))
- Which technique gives the lowest total cost for answering q range-sum queries on a fixed Python list of length n, where n and q are both 2…
- What is printed? python x = 7 print(x // 2 if x % 2 else x / 2, x > 3 > 2, not x > 3 == 4)
- What is printed? python print(pow(-2, 3, 5), pow(3, -1, 7), pow(2, 10, -7), (-2) 3 % 5)
- What is printed? python try: s = str(10 4301) print(len(s)) except ValueError: print('too many digits')