Question: Consider the following program. class my_iter: def _init_(self, nax, multiplier): self.current = 0 self. max = max self.multiplier = multiplier def_iter_(self): return self def_next_(self): if

 Consider the following program. class my_iter: def _init_(self, nax, multiplier): self.current

Consider the following program. class my_iter: def _init_(self, nax, multiplier): self.current = 0 self. max = max self.multiplier = multiplier def_iter_(self): return self def_next_(self): if self.current > = self.max: raise StopIteration self. current + = 1 return self.current + self.multiplier def regular_func(int_list, an_int): res = [] for i in int_list: res.append(i * an_int) return res def generator_func(int_list, an_int): for i in int_list: yield i * an_int x = regular_func([1, 2, 3], 5) y = generator_func([1, 2, 3], 5) print("x = ()".format(x)) print ("y = ()".format(y)) for i in range(10): try: print("next y = ()".format(next(y))) except StopIteration: print("stopped at ()". format(i)) break d = my_iter(3, 5) for i in d: print("next d {}". format(i)) (a) What is a generator function? Why is this useful? (b) What output will the above program produce

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!