Identifying the start of good data in a list

tkpmep at hotmail.com tkpmep at hotmail.com
Tue Aug 26 22:39:13 EDT 2008


On Aug 26, 7:23 pm, Emile van Sebille <em... at fenx.com> wrote:
> tkp... at hotmail.com wrote:
> > I have a list that starts with zeros, has sporadic data, and then has
> > good data. I define the point at  which the data turns good to be the
> > first index with a non-zero entry that is followed by at least 4
> > consecutive non-zero data items (i.e. a week's worth of non-zero
> > data). For example, if my list is [0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
> > 9], I would define the point at which data turns good to be 4 (1
> > followed by 2, 3, 4, 5).
>
> > I have a simple algorithm to identify this changepoint, but it looks
> > crude: is there a cleaner, more elegant way to do this?
>
>  >>> for ii,dummy in enumerate(retHist):
> ...     if 0 not in retHist[ii:ii+5]:
> ...         break
>
>  >>> del retHist[:ii]
>
> Well, to the extent short and sweet is elegant...
>
> Emile

This is just what the doctor ordered. Thank you, everyone, for the
help.

Sincerely

Thomas Philips



More information about the Python-list mailing list