Jim Segrave wrote:
> In article <[EMAIL PROTECTED]>,
> Paddy <[EMAIL PROTECTED]> 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           ([EMAIL PROTECTED])

Yep, I still, purposfully, decided not to put any guard checks in
because:
  Its very easy to add.
  It detracts from the algorithm.
  It might never be called with an empty list in-situ.
  It is correct for the original posters testcases.
  Yah gotta leave-em something to do ;-)

But you-too are right. Don't just cut-n-paste newsgroup solutions. they
need testing for your particular use. I doubt anyone on C.L.P. would be
malicious, but your actual use of a function having a wider scope to
inputs than mentioned might be fairy common.

(Damn, I wanted to use 'caveat emptor', but it does not apply as
nothing is being bought. Oh well :-)

-- Pad.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to