ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
import itertools print(list(itertools.islice(itertools.count(5, 2), 4)))
- A. [5, 6, 7, 8]
- B. [0, 2, 4, 6]
- C. [5, 7, 9, 11]
- D. [5, 7, 9]
Correct answer: C. [5, 7, 9, 11]
itertools.count(5, 2) is an infinite stream starting at 5, stepping by 2. islice takes the first 4 values: 5, 7, 9, 11.
More Python Programming questions
- What is printed? python import itertools print(list(itertools.chain([1, 2], [3, 4]))) print(list(itertools.chain.fromiterable([[1, 2], [3…
- What is printed? python import itertools print(list(itertools.combinations([1, 2, 3, 4], 2)))
- What is printed? python import itertools print(list(itertools.accumulate([1, 2, 3, 4]))) print(list(itertools.accumulate([1, 2, 3, 4]…
- What is printed? python print(list(zip([1, 2, 3], [4, 5], [6, 7, 8, 9]))) from itertools import ziplongest print(list(ziplongest([1, 2…
- What is printed? python print(list(enumerate(["a", "b", "c"], start=5)))
- What is printed? python from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass try: s = Shape() except…