Identifying the start of good data in a list

George Sakkis george.sakkis at gmail.com
Wed Aug 27 19:14:25 EDT 2008


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...



More information about the Python-list mailing list