Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the generator function genInf(aList) that takes in a Python list and returns a generator which yields all the items in the provided list one

Write the generator function genInf(aList) that takes in a Python list and returns a generator which yields all the items in the provided list one by one in an infinite loop. Do not use the Tab key to denote indentation, instead, use the space bar

def genInf(aList):

'''

>>> g = genInf([5,'a',2])

>>> next(g)

5

>>> next(g)

'a'

>>> next(g)

2

>>> next(g)

5

>>> next(g)

'a'

>>> next(g)

2

'''

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

Students also viewed these Programming questions

Question

Why does the Fed buy government securities during a recession?

Answered: 1 week ago