Identifying the start of good data in a list

castironpi castironpi at gmail.com
Wed Aug 27 17:48:53 EDT 2008


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?



More information about the Python-list mailing list