How to split a list by a changing step size?
<p>I have a list that I want to split up in to variable steps sizes. For example, if I have a list from 1 to 100, at the end of each iteration, I would want the output to be:</p>

<pre><code>[1, 2, 3] 
[4, 5, 6, 7, 8]
[9, 10, 11, 12, ..., 15]
[16, 17, ..., 25]
</code></pre>

<p>The length of the first list is 3, then 5, then, 7, then 9.</p>

<p>What I have is this</p>

<pre><code>lst = list(range(1,101))
odd = 3
for i in range(0, len(lst), odd):
    print(lst[i:i+odd])
    odd += 2
</code></pre>

<p>I know it does not work, but I don't know what needs to change.</p>

<p>Note that the indices to begin a slice at are given by the closed form:</p>

<pre><code>n**2 - 1 
</code></pre>

<p>Therefore:</p>

<pre><code>&gt;&gt;&gt; [lst[n**2-1:(n+1)**2-1] for n in range(1, 10)]
[[1, 2, 3],
 [4, 5, 6, 7, 8],
 [9, 10, 11, 12, 13, 14, 15],
 [16, 17, 18, 19, 20, 21, 22, 23, 24],
 [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],
 [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48],
 [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
 [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80],
 [81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]]
</code></pre>

python list for-loop