Question: Solve Fix a Recursive Function A friend tried to write a recursive function reverseList that reverses the elements of a list. For example, reverseList([1,2,3]) should
Solve
Fix a Recursive Function A friend tried to write a recursive function reverseList that reverses the elements of a list. For example, reverseList([1,2,3]) should return [3,2,1]. Your friend's implementation below does not work as expected because they are new to recursion and mixed up the iterative version of the function (that uses a loop) and the recursive one. Fix your friend's code by implementing the function recursively, similar to the examples you have seen in class. Your code snippet should define the following function: Name Type reverseList function user_code.py Ej 1- def reverseList(lst): 2+ if lenClst) == @: 3 return 4- else: 5 result = 6~ for x in lst: 7 result = [x] + reverseList(1st[1:]) 8 return resultStep 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
