Re: Identifying the start of good data in a list

2008-08-29 Thread castironpi
On Aug 29, 9:43 am, Jorgen Grahn <[EMAIL PROTECTED]> wrote: > On 27 Aug 2008 15:50:14 GMT, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > > > > > On Tue, 26 Aug 2008 17:04:19 -0700, tdmj wrote: > > >> On Aug 26, 5:49 pm, [EMAIL PROTECTED] wrote: > >>> I have a list that starts with zeros, has sporadi

Re: Identifying the start of good data in a list

2008-08-29 Thread Jorgen Grahn
On 27 Aug 2008 15:50:14 GMT, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Tue, 26 Aug 2008 17:04:19 -0700, tdmj wrote: > >> On Aug 26, 5:49 pm, [EMAIL PROTECTED] 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

Re: Identifying the start of good data in a list

2008-08-28 Thread tdmj
On Aug 27, 11:50 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Tue, 26 Aug 2008 17:04:19 -0700, tdmj wrote: > > On Aug 26, 5:49 pm, [EMAIL PROTECTED] wrote: > >> I have a list that starts with zeros, has sporadic data, and then has > >> good data. I define the point at whi

Re: Identifying the start of good data in a list

2008-08-28 Thread castironpi
On Aug 27, 3:42 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > Below are two more versions that pass all the doctests: the first > works only for lists and modifies them in place and the second works > for arbitrary iterables: > > def clean_inplace(seq, good_ones=4): >     start = 0 >     n = len(s

Re: Identifying the start of good data in a list

2008-08-28 Thread Gerard flanagan
George Sakkis wrote: On Aug 27, 3:00 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] 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 fol

Re: Identifying the start of good data in a list

2008-08-27 Thread castironpi
On Aug 27, 6:14 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Aug 27, 5:48 pm, castironpi <[EMAIL PROTECTED]> wrote: > > > > > On Aug 27, 4:34 pm, [EMAIL PROTECTED] wrote: > > > > George Sakkis: > > > > > This seems the most efficient so far for arbitrary iterables. > > > > This one probably sc

Re: Identifying the start of good data in a list

2008-08-27 Thread George Sakkis
On Aug 27, 5:48 pm, castironpi <[EMAIL PROTECTED]> wrote: > On Aug 27, 4:34 pm, [EMAIL PROTECTED] 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): > >

Re: Identifying the start of good data in a list

2008-08-27 Thread George Sakkis
On Aug 27, 5:34 pm, [EMAIL PROTECTED] wrote: > George Sakkis: > > > This seems the most efficient so far for arbitrary iterables. > > This one probably scores well with Psyco ;-) I think if you update this so that it returns the "good" iterable instead of the starting index, it is equivalent to Ge

Re: Identifying the start of good data in a list

2008-08-27 Thread castironpi
On Aug 27, 4:34 pm, [EMAIL PROTECTED] 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: >          

Re: Identifying the start of good data in a list

2008-08-27 Thread bearophileHUGS
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): """ >>> start_good = start_good3 >>> start_good([0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 4 >>> start_good([]) -1

Re: Identifying the start of good data in a list

2008-08-27 Thread George Sakkis
On Aug 27, 3:00 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] 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

Re: Identifying the start of good data in a list

2008-08-27 Thread George Sakkis
On Aug 26, 10:39 pm, [EMAIL PROTECTED] wrote: > On Aug 26, 7:23 pm, Emile van Sebille <[EMAIL PROTECTED]> wrote: > > > > > [EMAIL PROTECTED] 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

Re: Identifying the start of good data in a list

2008-08-27 Thread Gerard flanagan
[EMAIL PROTECTED] 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 da

Re: Identifying the start of good data in a list

2008-08-27 Thread Steven D'Aprano
On Tue, 26 Aug 2008 17:04:19 -0700, tdmj wrote: > On Aug 26, 5:49 pm, [EMAIL PROTECTED] 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

Re: Identifying the start of good data in a list

2008-08-26 Thread Scott David Daniels
[EMAIL PROTECTED] 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 da

Re: Identifying the start of good data in a list

2008-08-26 Thread Terry Reedy
Matthew Fitzgibbons wrote: [EMAIL PROTECTED] wrote: reHist = [0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] count = 0 for i, d in enumerate(reHist): if d == 0: count = 0 else: count += 1 if count == 5: break else: raise Exception("No data found") reHist = re

Re: Identifying the start of good data in a list

2008-08-26 Thread tkpmep
On Aug 26, 7:23 pm, Emile van Sebille <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] 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 a

Re: Identifying the start of good data in a list

2008-08-26 Thread tdmj
On Aug 26, 5:49 pm, [EMAIL PROTECTED] 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 w

Re: Identifying the start of good data in a list

2008-08-26 Thread Emile van Sebille
[EMAIL PROTECTED] 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 da

Re: Identifying the start of good data in a list

2008-08-26 Thread Mensanator
On Aug 26, 4:49 pm, [EMAIL PROTECTED] 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 w

Re: Identifying the start of good data in a list

2008-08-26 Thread Matthew Fitzgibbons
[EMAIL PROTECTED] 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 da

Re: Identifying the start of good data in a list

2008-08-26 Thread bearophileHUGS
Sorry, in the Psyco version replace this line: for i, el in enumerate(alist): With: for i in xrange(len(alist)): because Psyco doesn't digest enumerate well. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Identifying the start of good data in a list

2008-08-26 Thread bearophileHUGS
First solutions I have found, not much tested beside the few doctests: from itertools import islice def start_good1(alist, good_ones=4): """ Maybe more efficient for Python >>> start_good = start_good1 >>> start_good([0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 4 >>> start_go

Identifying the start of good data in a list

2008-08-26 Thread tkpmep
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 lis