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>Daniel's answer is the most concise one, but I'd like to point out that sometimes, you have a more complex situation and want to have the same slices from different iterables. Then you can also go along and store the actual <code>slice(start,stop[,step])</code> objects that python generates when you write <code>[start:stop:step]</code> in a list and use that. E.g.:</p>

<pre><code>r1 = range(1,101)
r2 = list(reversed(r1))

slices = [slice(0,5,3)]
for i in range(20):
    slices.append( slice(
                         slices[-1].stop,
                         slices[-1].stop + slices[-1].step + 1,
                         slices[-1].step + 1)
                 )

print [ (r1[s],r2[s]) for s in slices ]
</code></pre>

python list for-loop