Identifying the start of good data in a list

castironpi castironpi at gmail.com
Wed Aug 27 19:43:33 EDT 2008


On Aug 27, 6:14 pm, George Sakkis <george.sak... at gmail.com> wrote:
> On Aug 27, 5:48 pm, castironpi <castiro... at gmail.com> wrote:
>
>
>
> > On Aug 27, 4:34 pm, bearophileH... at lycos.com wrote:
>
> > > George Sakkis:
>
> > > > This seems the most efficient so far for arbitrary iterables.
>
> > > This one probably scores well with Psyco ;-)
>
> > > def start_good3(seq, good_ones=4):
> > >     n_good = 0
> > >     pos = 0
> > >     for el in seq:
> > >         if el:
> > >             if n_good == good_ones:
> > >                 return pos - good_ones
> > >             else:
> > >                 n_good += 1
> > >         elif n_good:
> > >                 n_good = 0
> > >         pos += 1
> > >     if n_good == good_ones:
> > >         return pos - good_ones
> > >     else:
> > >         return -1
>
> > > Bye,
> > > bearophile
>
> > There, that's the regular machine for it.  Too much thinking in
> > objects, and you can't even write a linked list anymore, right?
>
> And you're still wondering why do people killfile you or think you're
> a failed AI project...

Just jumping on the bandwagon, George.  And you see, everyone else's
passed the doctests perfectly.  Were all the running times O( n* k )?



More information about the Python-list mailing list