I am creating a program that accepts an array and reverses it, it must include a recursive function. I am having an issue where it is returning None
instead of the reversed array. Running it through a debugger and creating stop points at the return and the call of the recursive function shows that it does indeed reverse the function properly, but fails to return the array, is there something I am missing or have done wrong for it to not return the array?
Code:
def reverse(my_list, index = 0):
if index == len(my_list)//2: #The program will return the list as soon as it reaches the middle entry
return my_list
elif index <len(my_list)/2:
temp = my_list[index]
my_list[index] = my_list[(len(my_list)-1)-index]
my_list[(len(my_list)-1)-index] = temp
reverse(my_list,index+1)
def main():
myList = [0,1,2,3,4,5,6,7,8,9]
print(str(myList))
print(str(reverse(myList)))
if __name__ == '__main__':
main()