Jim Segrave wrote: > In article <[EMAIL PROTECTED]>, > Paddy <[EMAIL PROTECTED]> wrote: > >=== interv2 === > >>>> 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]] > > > >=== END interv2 === > > This doesn't actually run, changing it to make it do so: > > def interv2(inlist): > tmp = valinc = 0 > for i,val in enumerate(inlist): > if i==0: > tmp = val > valinc = val + 1 > elif val != valinc: > yield [tmp, valinc] > tmp = val > valinc = val+1 > yield [tmp, valinc] > > it now works, but returns [0, 0] when passed an empty list, when it > should return nothing at all > -- > Jim Segrave ([EMAIL PROTECTED]) Jim, I had tabs/spaces indent problems when cut-n-pasting.
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]] -- http://mail.python.org/mailman/listinfo/python-list