ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
from itertools import count, islice
print(list(zip('abc', count(10, 5))), list(islice(count(1, 2), 3)))
  1. A. [('a', 10), ('b', 15), ('c', 20)] [1, 2, 3]
  2. B. [('a', 10), ('b', 15), ('c', 20)] [1, 3, 5]
  3. C. [('a', 10), ('b', 15)] [1, 3, 5]
  4. D. [('a', 5), ('b', 10), ('c', 15)] [1, 3, 5]

Correct answer: B. [('a', 10), ('b', 15), ('c', 20)] [1, 3, 5]

zip stops at the shorter input, here the three-letter string, and count(10, 5) steps by 5. islice(count(1, 2), 3) takes 1, 3 and 5.

More Python Programming questions

Exams that ask this topic