I need to complete this code for school.
The program should find an index of sequence split in the list.
For example for input which is a list like this
[66, 81, 83, 96, 13, 19, 30, 41, 44, 57]
the correct output should be 4 (index of number where the sequence is interrupted - 96)
My function is able to find the split but I don't know how to return an index of that split. It always return incorrect answer.
Here is my code:
def findSplit( list ):
if len(list)%2 == 0:
if list[(len(list)//2)-1] == list[0]:
return 1
elif list[(len(list)//2)-1]<list[0]:
return findSplit(list[:(len(list)//2)]) - len(list)//2
elif list[(len(list)//2)-1]>list[0]:
return findSplit(list[(len(list)//2)-1:]) + len(list)//2
elif len(list)%2 != 0:
if list[(len(list)//2)]<list[0]:
return findSplit(list[:(len(list)//2)+1]) - len(list)//2
elif list[(len(list)//2)]>list[0]:
return findSplit(list[(len(list)//2):]) + len(list)//2
if __name__ == "__main__":
list = [ 66, 81, 83, 96, 13, 19, 30, 41, 44, 57 ]
line = input().strip().split()
if line != []:
list = []
for x in line:
list.append( int( x ) )
print(findSplit( list ))