ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools print(sum(a < b for a, b in itertools.pairwise([1, 3, 2, 5, 4, 6])))
- A. 4
- B. 5
- C. 3
- D. 2
Correct answer: C. 3
pairwise yields the five consecutive pairs (1,3), (3,2), (2,5), (5,4), (4,6). Of these, the pairs with an increase are (1,3), (2,5) and (4,6), so the sum of True values is 3.
More Python Programming questions
- What is printed? python import itertools print(list(itertools.batched(range(7), 3))[-1])
- What is printed? python import sys print(sys.getrecursionlimit())
- What is printed? python import sys sys.setrecursionlimit(50) def f(n): return 0 if n == 0 else 1 + f(n - 1) try: print(f(60)) except…
- What is printed? python from functools import lrucache @lrucache(None) def f(n): return n if n < 2 else f(n - 1) + f(n - 2) print(f(90))
- What is printed? python from functools import lrucache import sys sys.setrecursionlimit(1000) @lrucache(None) def f(n): return 0 if n == 0…
- What is printed? python g = {1: [2, 3], 2: [4], 3: [], 4: []} stack = [1] out = [] while stack: u = stack.pop() out.append(u)…