ProgrammingHardGATE CS · Product-company placement
What is printed? (Output lines are shown separated by " / ".)
What is printed? (Output lines are shown separated by " / ".)
it = iter([1, 2, 3, 4, 5, 6])
print([(a, b) for a, b in zip(it, it)], [x for x in iter([1, 2, 3]) if x != 2])
c = iter("abcdef")
print(list(zip(c, c, c)))- A. [(1, 2), (3, 4), (5, 6)] [1, 3] / [('a', 'b', 'c'), ('d', 'e', 'f')]
- B. [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)] [1, 3] / [('a', 'a', 'a')]
- C. [(1, 2), (3, 4), (5, 6)] [1, 3] / [('a', 'd'), ('b', 'e'), ('c', 'f')]
- D. [(1, 2), (3, 4), (5, 6)] [1, 2, 3] / [('a', 'b', 'c'), ('d', 'e', 'f')]
Correct answer: A. [(1, 2), (3, 4), (5, 6)] [1, 3] / [('a', 'b', 'c'), ('d', 'e', 'f')]
Passing the SAME iterator several times to zip makes each tuple pull consecutive items, which groups the stream into chunks of 2 (or 3).
More Python Programming questions
- What is printed? python s = {1, 2, 3} t = {3, 4} print(s | t, s & t, s - t, s ^ t, s >= {1, 2})
- What is printed? python a = {1, 2} b = a a |= {3} c = frozenset(a) a = a | {4} print(b, c, a, type(c | {9}).name)
- What is printed? python s = set() s.add((1, 2)) s.add((2, 1)) try: s.add([1]) except TypeError: s.add(frozenset([1]))…
- What is printed? python d = {"a": 1, "b": 2, "c": 3} del d["a"] d["a"] = 4 d.pop("b") d["b"] = 5 print(list(d.items()), next(iter(d))…
- What is printed? python class Key: def init(self, v): self.v = v def hash(self): return hash(self.v) def eq(self, o): return self.v == o.v…
- What is printed? python d = dict.fromkeys(range(3), 0) for k in d: d[k] += k e = {k: [] for k in "ab"} e["a"].append(1) f =…