ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
it = iter([1, 2, 3, 4, 5]) print(list(zip(it, it)))
- A. [(1, 2), (3, 4), (5,)]
- B. [(1, 2), (3, 4)]
- C. [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)]
- D. [(1, 2), (3, 4), (5, None)]
Correct answer: B. [(1, 2), (3, 4)]
Both arguments are the SAME iterator, so each tuple takes two values one after the other: (1, 2), then (3, 4). For the third tuple, 5 is taken but the second pull fails, so zip stops and 5 is dropped.
More Python Programming questions
- What is printed? python x = 1 x, y = x + 1, x 10 print(x, y)
- What is printed? python print(any([]), all([]), all([[]]))
- What is printed? python class C: n = 0 def init(self): C.n += 1 @classmethod def total(cls): return cls.n class D(C): pass D(); C(); D()…
- What is printed? python e = 5 try: 1 / 0 except ZeroDivisionError as e: pass try: print(e) except NameError: print("NameError")
- How many of the following statements about Python are correct? (i) A tuple that contains a list can be used as a dictionary key. (ii) A…
- What is printed? python a = [1, 2, 3] a += [4] a = a + [5] a.extend("67") print(a)