Re: Pattern Matching in Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg35854] Re: Pattern Matching in Lists
- From: daiyanh at earthlink.net (Daitaro Hagihara)
- Date: Sat, 3 Aug 2002 00:17:31 -0400 (EDT)
- References: <ah5qce$59o$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
It seemed strange that no one mentioned pattern matching construct of _?. Count[{1,1,1,0,0,1,0,1,0,0,1,0,0}, _?((t=#==0&&i==1;i=#;t)&)] ==> 4 If different tests are needed on the same data set, it'd be advised to make test functions such as f[x_]:=(t=x==0&&i==1;i=x;t) and run Count[w,_?f]. The reason why {___,1,0,___} doesn't work is because patterns are matched elementwise. DH