Python split a list into subsets based on pattern
<p>I'm doing this but it feels this can be achieved with much less code. It is Python after all. Starting with a list, I split that list into subsets based on a string prefix.</p>

<pre><code># Splitting a list into subsets
# expected outcome:
# [['sub_0_a', 'sub_0_b'], ['sub_1_a', 'sub_1_b']]

mylist = ['sub_0_a', 'sub_0_b', 'sub_1_a', 'sub_1_b']

def func(l, newlist=[], index=0):
    newlist.append([i for i in l if i.startswith('sub_%s' % index)])
    # create a new list without the items in newlist
    l = [i for i in l if i not in newlist[index]]

    if len(l):
        index += 1
        func(l, newlist, index)

func(mylist)
</code></pre>
