I have a list li = [1,2,3,4], I need to remove odd index from list each time, after removing odd index from a list I will get 2,4 then after again I need to remove odd element and I will get 4, which should be my output.
I tried solving this in Python:
li = [1,2,3,4,5]
arr = []
for i in range (len(li)):
if(i%2 == 0):
continue
arr.append(li[i])
for i in range (len(arr)):
if(i%2 == 0):
continue
print (arr[i])
But for same array i.e., li = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], i will get [4,8,12] and again removing odd indices from arr = [4,8,12]. I will get output 8 by removing odd index element. How can I do with more optimal solution?