grouping a flat list of number by range

Jim Segrave jes at
Fri Jun 2 01:13:44 CEST 2006

In article <1149202388.135494.148890 at>,
Paddy <paddy3118 at> wrote:
>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]

Still fails when passed an empty list, the initial assignment to tmp
is an IndexError

Jim Segrave           (jes at

More information about the Python-list mailing list