Question
Trying to create Python function continuous1234 that returns a never ending generator that yields the numbers 1,2,3,4 forever. Note: Have to use something from itertools
Trying to create Python function continuous1234 that returns a never ending generator that yields the numbers 1,2,3,4 forever. Note: Have to use something from itertools which i tried below but I keep getting False on iteration? # Here is what i have so far # def continuous1234(): """Return a generator that returns the numbers 1, 2, 3, 4 continuously.""" lst = ['1', '2', '3', '4'] pool = itertools.cycle(lst) for item in pool: yield from item
# This is how it should work # from app import continuous1234
n1234 = continuous1234() iter(n1234) == n1234 True next(n1234) == 1 True next(n1234) == 2 True next(n1234) == 3 True next(n1234) == 4 True next(n1234) == 1 True next(n1234) == 2 True next(n1234) == 3 True next(n1234) == 4 True next(n1234) == 1 True next(n1234) == 2 True [...etc...]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started