Python Programming - Generators - Discussion
Discussion Forum : Generators - General Questions (Q.No. 58)
58.
What is the purpose of the
itertools.cycle()
function when used with generators?
Answer: Option
Explanation:
itertools.cycle()
creates an infinite sequence of repeated values. When used with a generator, it continuously cycles through the values produced by the generator.
import itertools
def my_generator():
yield 1
yield 2
yield 3
cycled_generator = itertools.cycle(my_generator())
for _ in range(10):
print(next(cycled_generator))
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers