Solution Review: Return Numbers From n to 0

This lesson covers the Python code to return a list of numbers from n down to 0 using iterators.

We'll cover the following

Solution: Use Iterator

In this problem, you only had to edit the next method to include a reverse for loop; for i in range(self.n, -1, -1) where i is decremented once in every iteration. In line 11 of the code below, you append the value of i to the list in every iteration and return the list at the end of the method. In lines 14 and 15, you can test your code by creating an instance of the MyRange class and calling the next method.

Get hands-on with 1000+ tech skills courses.