Input:
data = [1, 2, 3, 4, 5, 6]
Output:
out = [[6],
[5, 4],
[3, 2, 1]]
Current solution:
end_value = 6
data = list(range(1,end_value+1)[::-1])
iterations = round(end_value**0.5)+1
last_index = [0]+[i*(i+1)+1 for i in range(iterations)]
out = [data[last_index[i]:last_index[i+1]] for i in range(len(last_index)-1)]
for p in out: print(p)
Question:
The code I’ve wrote above seems very overcomplicated.
Is it possible to do something similar, but in more pythonic
way using numpy
or itertools
?