I am trying to continually separate a list into left and right sides until no more half lists can be made and print them each time. Also I try to choose left or right side based on even or odd iterations.
Code:
low = 0
high = n
i=0
a = len(L1)
b = len(L2)
while a > 0 and b>0:
mid = (low + high)// 2
if i%2==0:
print(L[low:mid])
low = mid + 1
print(L[mid:high])
else:
print(L[low:mid])
high = mid - 1
print(L[low:high])
print(L[mid:high])
i=i+1
L = [1, 2, 3, 4, 5]
# should print:
[1, 2, 3]
[4, 5]
[1, 2]
[3]
[4]
[5]
Any help please