grouping a flat list of number by range

Paddy paddy3118 at
Fri Jun 2 00:53:08 CEST 2006

I did a little re-arranging of the generator version:

def interv3(inlist):
    tmp = inlist[0]
    valinc = tmp+1
    for val in inlist[1:]:
        if val != valinc:
            yield [tmp, valinc];
            tmp = val
        valinc = val+1
    yield [tmp, valinc]

More information about the Python-list mailing list