ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(zip(*[[1, 2, 3], [4, 5]])), list(zip(*[[1, 2], [3, 4, 5]], strict=False)))
- A. [(1, 4), (2, 5)] [(1, 3), (2, 4), (None, 5)]
- B. [(1, 4), (2, 5), (3, None)] [(1, 3), (2, 4), (None, 5)]
- C. [(1, 4), (2, 5)] [(1, 3), (2, 4)]
- D. [(1, 4), (2, 5), (3, None)] [(1, 3), (2, 4)]
Correct answer: C. [(1, 4), (2, 5)] [(1, 3), (2, 4)]
zip stops at the shortest input when strict is False (the default). Both calls therefore keep only the shared positions, so the extra 3 and 5 are dropped.
More Python Programming questions
- What is printed? python from collections import deque a = [1, 3, -1, -3, 5, 3, 6, 7] k = 3 dq = deque() out = [] for i, x in enumerate(a)…
- What is printed? python import heapq class T: def init(self, p, n): self.p = p self.n = n def lt(self, o): return self.p > o.p h = [] for…
- What is printed? python class P: def init(self, x): self.x = x def eq(self, o): return self.x == o.x try: print(len({P(1)})) except…
- What is printed? python from functools import reduce print(reduce(lambda a, b: a b, range(1, 21), 1), reduce(lambda a, b: a + b, [], 0))
- What is printed? python try: print(sorted([3, None, 1])) except TypeError as e: print(e)
- What is printed? python def flat(x): for y in x: if isinstance(y, list): yield from flat(y) else: yield y print(list(flat([1, [2, [3…