grouping a flat list of number by range

Jim Segrave jes at nl.demon.net
Thu Jun 1 19:13:44 EDT 2006


In article <1149202388.135494.148890 at u72g2000cwu.googlegroups.com>,
Paddy <paddy3118 at netscape.net> 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 jes-2.demon.nl)




More information about the Python-list mailing list