Collect subsequences of consecutive integers
@Peter Taylor has a good idea, but there is more to be improved

You should add some tests

Python is often described as Batteries included
This is a perfect example to use itertools.groupby()



from itertools import groupby
import doctest

def extract_seq(seq):
    &quot;&quot;&quot;
    Splits sequence into consecutive lists
    
    args:
        seq (list): A sorted sequence

    &gt;&gt;&gt; extract_seq([1,2, 4,5, 8,9])
    [[1, 2], [4, 5], [8, 9]]

    &gt;&gt;&gt; extract_seq([1,2,3])
    [[1, 2, 3]]

    &gt;&gt;&gt; extract_seq([1,2,3,7,8,9])
    [[1, 2, 3], [7, 8, 9]]

    &gt;&gt;&gt; extract_seq([1,2,3,10])
    [[1, 2, 3], [10]]
    &quot;&quot;&quot;
    return [
        [x for _, x in g]
        for k, g in groupby(
            enumerate(seq), 
            lambda i_x : i_x[0] - i_x[1]
        )
    ]

if __name__ == &quot;__main__&quot;:
    doctest.testmod()