ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools g = iter(range(10)) print(list(itertools.islice(g, 2, 7, 2)), next(g))
- A. [2, 4, 6] 7
- B. [2, 4, 6] 8
- C. [2, 4] 6
- D. [2, 4, 6] 6
Correct answer: A. [2, 4, 6] 7
islice(it, 2, 7, 2) yields the items at indices 2, 4 and 6 and stops without reading index 7. The next item left in the shared iterator is 7.
More Python Programming questions
- What is printed? python import itertools print(list(itertools.ziplongest('ab', 'xyz', fillvalue='-')))
- What is printed? python import itertools print(sum(a < b for a, b in itertools.pairwise([1, 3, 2, 5, 4, 6])))
- 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))