I’m trying to get a better understanding of recursion using the merge sort algorithm using Python 2.7. I have written a small snippet of code to break down a list recursively. The code seems to work fine except for the last step. For the base case, the program is supposed to return a list of size 1. However, it is returning the value “none”. Where am I going wrong?
mylist = [14,88,2,14,9,123,1,5]
def concour(thelist):
mid = len(thelist) / 2
LeftSide = thelist[:mid]
print LeftSide,'length is ', len(LeftSide)
if len(LeftSide) == 1: #the base case here
print LeftSide
return LeftSide
else:
concour(LeftSide) #recursive call
print concour(mylist)
"""
[14, 88, 2, 14] length is 4
[14, 88] length is 2
[14] length is 1
[14]
None
"""