Python Question Write a function which is passed a list and
Python Question:
Write a function which is passed a list, and returns a list whose elements are in the reverse order of the original list. You may not use the built-in Python reverse method.
The solution must be recursive
For example:
>>> reverse([1, 2, 3])
[3, 2, 1]
Solution
Ans.
def reverseList(l):
if len(l) == 0: return []
return [l[-1]] + reverseList(l[:-1])
l = [2, 3, 5]
print reverseList(l)
