ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
print(list(zip(*[iter(range(6))] * 2)))
- A. [(0, 0), (1, 1), (2, 2)]
- B. [(0, 1), (2, 3)]
- C. [(0, 1), (2, 3), (4, 5)]
- D. [(0, 1), (2, 3), (4, 5), (6, 7)]
Correct answer: C. [(0, 1), (2, 3), (4, 5)]
[iter(...)] * 2 repeats one iterator object, so zip takes consecutive pairs from the same iterator. The pairs are (0, 1), (2, 3) and (4, 5).
More Python Programming questions
- What is printed? python print(sum(range(106)) % 7)
- What is printed? python print(12 & -12, 12 ^ 12 >> 1)
- What is printed? python print(list(map(lambda a, b: a b, [1, 2, 3], [4, 5])))
- What is printed? python print(max([], default=-1), min(range(0), default='e'))
- What is printed? python from itertools import takewhile, dropwhile a = [1, 3, 5, 2, 7, 1] print(list(takewhile(lambda x: x % 2, a))…
- What is printed? python print(next(iter([]), 'none'), next(iter([7])))