What is the fastest way to generate a list of the lengths of sub-strings in a string, given a separator?
===

I have a string and I need to generate a list of the lengths of all the sub-strings terminating in a given separator.

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.

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

    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)]

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.

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

