Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions

Question

=+19.1. Suppose that u(12) and fe L". Show that IfIl, Ilfilo.

Answered: 1 week ago