ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools
print(list(itertools.zip_longest('ab', 'xyz', fillvalue='-')))- A. [('a', 'x'), ('b', 'y'), ('c', 'z')]
- B. [('a', 'x'), ('b', 'y'), ('-', 'z')]
- C. [('a', 'x'), ('b', 'y')]
- D. [('a', 'x'), ('b', 'y'), ('z', 'z'), ('-', '-')]
Correct answer: B. [('a', 'x'), ('b', 'y'), ('-', 'z')]
zip_longest keeps going until the longest input is exhausted, filling the shorter one with fillvalue. zip alone would stop after two pairs.
More Python Programming questions
- 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))
- What is printed? python from functools import lrucache import sys sys.setrecursionlimit(1000) @lrucache(None) def f(n): return 0 if n == 0…