Question: 6. (20 pts) reverse iter: Write a generator function reverse_iter that accepts an iterable sequence and yields the items in reverse order. Think about what

 6. (20 pts) reverse iter: Write a generator function reverse_iter thataccepts an iterable sequence and yields the items in reverse order. Think

6. (20 pts) reverse iter: Write a generator function reverse_iter that accepts an iterable sequence and yields the items in reverse order. Think about what we learned in week 3, and also what we learned in week 2 about how to reverse a sequence. Note that after using reverse iter, the original sequence should be unchanged. Don't use built-in functions or methods like reverse(), reversed(), iter) . Please note that this should also work when the input is a tuple (eg, nums = (1, 2, 3, 4) in the example below), because tuples are sequences. >from HW6 import reverse_iter >>nums[8, 3, 6] >>>it -reverse iter (nums) >>next (it) 6 True >>next (it) >>next (it) >>next (it) Traceback (most recent call last): StopIteration >nums [8, 3, 6] >>it -reverse iter(items) >iter(it) is it True >>next (it) >>next (it) >>next (it) >>next (it) Traceback (most recent call last) StopIteration

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!