Question: In a new file reverse.py, write two functions, one recursive and the other iterative, that take in a list and return a new list with
- In a new file reverse.py, write two functions, one recursive and the other iterative, that take in a list and return a new list with the elements in reverse order. These functions should be called reverse_r and reverse_i respectively. Note that if you Google for how to reverse something, you will likely find some answers about list slicing like [::-1]. For this problem, we want you not to use this.
- Write some test code to test your two reverse functions out.
Input/Output Examples:
- reverse_i(['h', 'e', 'l', 'l', 'o']) # ['o', 'l', 'l', 'e', 'h']
- reverse_r(['h', 'e', 'l', 'l', 'o']) # ['o', 'l', 'l', 'e', 'h']
- reverse_i([1, 2, 3, 4, 5]) # [5, 4, 3, 2, 1]
Note that:
- You should write tests for all of the functions you write for this lab. Write the tests before you write the code, and put them after the if __name__ == '__main__': line. We're going to import the functions from your files for testing and, if you don't put your tests after this line (and indented to the if block), then it might confuse our testing code. Also, this if good programming practice.
- There are likely to be built-in functions for a number of the things we're asking you to do for this lab. Please don't use them. If you do, you'll get zero points for that part of the assignment, since we want you to write them from scratch (this time).
- The amplitude filter only affects sensor readings beyond a certain threshold. These sensor readings get clipped to the maximum allowed amplitude.
- When you write the variable-width mean filter, you might find array slicing useful. Also, the filtered arrays will be shorter than the input arrays. For a filter with width 3, the filtered lists will be 2 elements shorter than the original list. For a width of 5, it will be 4 shorter, and so on.
- Use Python 3.8
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
