Split a string into unevenly sized chunks in a repeating pattern
<p>I have a string representing a series of bits:</p>

<pre><code>bit_stream = "10100101011101011101011"  # ...(so on)
</code></pre>

<p>I need to split this into unevenly sized chunks in a repeating pattern. The first chunk should be length 1, followed by a chunk of length 8, then a chunk of length 2, and so on until the bits are exhausted:</p>

<pre><code>result = ["1", "01001010", "11", "1", "01011101", "01", "1"]  # ...(so on)
</code></pre>

<pre><code>bit_stream = "10100101011101011101011"
fmt = [1,8,2]
i = 0
j = 0
lenb = len( bit_stream )
result = []

while True:
    l = j + fmt[i]
    if l &lt; lenb:
        result.append( bit_stream[j:l] )
    else:
        result.append( bit_stream[j:lenb] )
        break
    j = l
    i = i + 1
    if i &gt; 2:
        i = 0
print result
</code></pre>

<p>Output:</p>

<pre><code>['1', '01001010', '11', '1', '01011101', '01', '1']
</code></pre>

python python-2.7 split