ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools print(list(itertools.batched(range(7), 3))[-1])
- A. [5, 6]
- B. (4, 5, 6)
- C. 7
- D. (6,)
Correct answer: D. (6,)
batched (Python 3.12+) yields tuples of at most n items. The last batch holds only the leftover item, 6, and is returned as the 1-tuple (6,).
More Python Programming questions
- 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)…
- What is printed? python s = list(range(10)) print(s[8:2:-3], s[::-4], s[-3:])