Proper way to split Python list into list of lists on matching list item delimeter
<pre><code>list = ['a', 'b', 'c', '', 'd', 'e', 'f', '', 'g','h','i']

def chunk(list, delim):
    ct = list.count(delim)
    chunks = [[]] * (ct+1)
    for iter in range(ct):
        idx = list.index(delim)
        chunks[iter] = list[:idx]
        list = list[idx+1:]
    chunks[ct] = list
    return chunks

print chunk(list, '')
</code></pre>

<p>Produces:</p>

<pre><code>[['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
</code></pre>

<p>Which is what I want, but I feel like this is the 'c' way to accomplish this. Is there a more pythonistic construct I should know? </p>

<p>Focusing on the iterability of lists in Python:</p>

<pre class="lang-py prettyprint-override"><code>list = ['a', 'b', 'c', '', 'd', 'e', 'f', '', 'g','h','i']

def chunk(list, delim):
    aggregate_list = []
    current_list = []

    for item in list: 
      if item == delim:
        aggregate_list.append(current_list)
        current_list = []; 

        # You could also do checking here if delim is starting 
        #  index or ending index and act accordingly 
      else:
        current_list.append(item)

    return aggregate_list

print chunk(list, '')
</code></pre>

python