This code just find the largest number by divide and conquer algorithm. The code by itself works perfectly and finds the larges number and stores in my_data[0]. It prints the largest number correctly. But when I try to return it and store in 'val' variable, 'None' gets stored and not the largest number. Why the return statement is returning only 'none' instead my_data[0].. ?? I am not able to proceed the code since the return value is not correct. Can anyone say what fault is this ? Thanks in advance..
def largest(my_data):
if len(my_data) == 1:
print my_data[0]
return my_data[0]
else:
alist = []
blist = []
for i in range(0,len(my_data),2):
if my_data[i] > my_data[i+1]:
alist.append(my_data[i])
blist.append(my_data[i+1])
else:
alist.append(my_data[i+1])
blist.append(my_data[i])
my_data = list(alist)
largest(my_data)
my_data = [12,45,63,13,76,87,23,85,56,123,7856,132,786,124,756,25366468]
val = largest(my_data)
print val
max(my_data), it'd be simpler to just iterate through the list, keeping track of the biggest element you've seen so far.