def subdivide(length, parts=None, max_length=None):
if max_length:<EOL><INDENT>i1 = <NUM_LIT:0><EOL>done = False<EOL>while not done:<EOL><INDENT>i2 = min(length, i1 + max_length)<EOL>yield i1, i2<EOL>i1 = i2<EOL>if i1 == length:<EOL><INDENT>done = True<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>part_length = int(math.ceil(float(length) / parts))<EOL>for index in range(parts):<EOL><INDENT>i1, i2 = index * part_length, min(length, (index + <NUM_LIT:1>) * part_length)<EOL>yield i1, i2<EOL><DEDENT><DEDENT>
Generates a list with start end stop indices of length parts, [(0, length/parts), ..., (.., length)]