ProgrammingVery hardInfosys HackWithInfy · TCS CodeVita
What is printed?
What is printed?
it = iter(range(7)) print(list(zip(it, it)), list(it))
- A. [(0, 1), (2, 3), (4, 5)] [6]
- B. [(0, 1), (2, 3), (4, 5), (6, None)] []
- C. [(0, 1), (2, 3), (4, 5)] [6, 7]
- D. [(0, 1), (2, 3), (4, 5)] []
Correct answer: D. [(0, 1), (2, 3), (4, 5)] []
zip pulls from the first iterator before the second, so the value 6 taken from the first iterator is discarded when the second one is exhausted. The shared iterator ends empty.
More Python Programming questions
- What is printed? python print(sum([0.1] 10) == 1.0, sum([0.1] 10), round(sum([0.1] 10), 2))
- What is printed? python x = (5) y = (5,) print(type(x).name, type(y).name, len(y), ((5),) == (5,))
- What is printed? python a = {1, 2, 3} b = {3, 4} print(a ^ b, a.issubset({1, 2, 3, 4}), sorted(a - b, reverse=True), b > {3})
- What is printed? python import math print(math.floor(-2.5), math.trunc(-2.5), -7.5 // 2, divmod(7.5, 2))
- What is printed? python def dfs(g, s): seen, out, st = set(), [], [s] while st: u = st.pop() if u in seen: continue seen.add(u)…
- What is printed? python def hanoi(n, a, b, c, out): if n == 0: return hanoi(n - 1, a, c, b, out) out.append((a, c)) hanoi(n - 1, b, a, c…