When you are passing the arr[:-1], the copy of an array is created and changes aren't reflected in your original list.
To implement it:
def sort(arr, index):
if(len(arr) == 2):
if(arr[index-1] > arr[index]):
arr[index-1], arr[index] = arr[index], arr[index-1]
return arr
arr = sort(arr[:index], index-1)+[arr[index]]
if(arr[index-1] > arr[index]):
arr[index-1], arr[index] = arr[index], arr[index-1]
return arr
arr = [1,4,2,8,5,6]
arr = sort(arr, len(arr)-1)
print(arr)
Improve your knowledge in data science from scratch using data scientist