Re: grouping a flat list of number by range



In article <1149202780.780252.242110@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Paddy <paddy3118@xxxxxxxxxxxx> wrote:

What I ran was more like the version below, but i did a quick
separation of the line that has the ';' in it and goofed.

def interv2(inlist):
... for i,val in enumerate(inlist):
... if i==0:
... tmp = val
... elif val != valinc:
... yield [tmp, valinc]; tmp = val
... valinc = val+1
... yield [tmp, valinc]
...
list(interv2(inlist))
[[3, 4], [6, 9], [12, 14], [15, 16]]

Fails on an empty list, as tmp is not defined when it hits the yield


--
Jim Segrave (jes@xxxxxxxxxxxxxx)

.



Relevant Pages

  • Re: grouping a flat list of number by range
    ... Jim Segrave wrote: ... Paddy wrote: ... separation of the line that has the ';' in it and goofed. ... It is correct for the original posters testcases. ...
    (comp.lang.python)
  • Re: Bidirectional Generators
    ... Paddy wrote: ... I did get my generator working, and then ... actually uses yield _and_ sendto do anything that isn't in the ... original PEP. ...
    (comp.lang.python)
  • Re: Separation,Power and Countability.
    ... definability plus your restricted separation would yield ... inconsistency. ...
    (sci.math)