What is the fastest way to generate a list of the lengths of sub-strings in a string, given a separator?
<p>I have a string and I need to generate a list of the lengths of all the sub-strings terminating in a given separator.</p>

<p>For example: string = 'a0ddb0gf0', separator = '0', so I need to generate: lengths = [2,4,3], since len('a0')==2, len('ddb0')=4, and len('gf0')==3.</p>

<p>I am aware that it can be done by the following (for example):</p>

<pre><code>separators = [index for index in range(len(string)) if string[index]==separator]
lengths = [separators[index+1] - separators[index] for index in range(len(separators)-1)]
</code></pre>

<p>But I need it to be done extremely fast (on large amounts of data). Generating an intermediate list for large amounts of data is time consuming.</p>

<p>Is there a solution that does this neatly and fast (py2.7)?</p>
