ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
import itertools print(list(itertools.accumulate([1, 2, 3, 4]))) print(list(itertools.accumulate([1, 2, 3, 4], func=lambda a, b: a * b)))
- A. [1, 2, 3, 4] [1, 2, 6, 24]
- B. [1, 3, 6, 10] [1, 2, 6, 24]
- C. [1, 3, 6, 10] [1, 2, 3, 4]
- D. [10, 10, 10, 10] [24, 24, 24, 24]
Correct answer: B. [1, 3, 6, 10] [1, 2, 6, 24]
Default accumulate computes running sums: 1, 1+2=3, 3+3=6, 6+4=10. With func=multiply, it computes a running product instead: 1, 1*2=2, 2*3=6, 6*4=24.
More Python Programming questions
- What is printed? python print(list(zip([1, 2, 3], [4, 5], [6, 7, 8, 9]))) from itertools import ziplongest print(list(ziplongest([1, 2…
- What is printed? python print(list(enumerate(["a", "b", "c"], start=5)))
- What is printed? python from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass try: s = Shape() except…
- What is printed? python class Meta(type): def new(mcs, name, bases, ns): print("creating", name) return super().new(mcs, name, bases, ns)…
- What is printed? python class Vec: def init(self, x, y): self.x, self.y = x, y def radd(self, o): return Vec(self.x + o, self.y + o) def…
- What is printed? python class Idx: def index(self): return 3 l = [0, 1, 2, 3, 4, 5] print(l[Idx()])