Identifying the start of good data in a list

Jorgen Grahn grahn+nntp at snipabacken.se
Fri Aug 29 10:43:52 EDT 2008


On 27 Aug 2008 15:50:14 GMT, Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
> On Tue, 26 Aug 2008 17:04:19 -0700, tdmj wrote:
>
>> On Aug 26, 5:49 pm, 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).
>
> ...
>
>> With regular expressions:
>
> Good grief. If you're suggesting that as a serious proposal, and not just 
> to prove it can be done, that's surely an example of "when all you have 
> is a hammer, everything looks like a nail" thinking.

Maybe I'm stumbling into a "REs are evil" flamewar here. Anyway:

He has a point though: this *can* be seen as a regex problem. Only a
solution which builds a string first is only good for laughs or
(possibly) quick hacks. What's missing is an RE library for lists of
objects, rather than just strings and Unicode strings.

Not sure such a library would be worth implementing -- problems like
this one are rare, I think.

/Jorgen

-- 
  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/     snipabacken.se>          R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list