Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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