list/sequence problem: a 'keep' list to a list of 'kept' lists
- To: mathgroup at smc.vnet.net
- Subject: [mg97147] list/sequence problem: a 'keep' list to a list of 'kept' lists
- From: mkr <MilesKRains at gmail.com>
- Date: Fri, 6 Mar 2009 04:26:41 -0500 (EST)
I have a list of Booleans, indicating whether prior values in sequence are to be 'kept'. I want to generate a list of accumulated 'kept' positions for each position in the sequence. The following code works, but I would love to see a cleaner, more obivous approach. Anyone? In[]= keepPrior= {False,True,False,True,False,False,True,True,True,False,True}; keptPriors=Function[aclist,If[Split[aclist][[-1,1]]==True,Range[Length [aclist]-Length[Split[aclist][[-1]]],Length[aclist]],{Length [aclist]}]]/@Rest[FoldList[Append,{},keepPrior]]; TableForm[Transpose[{keepPrior,ToString/@keptPriors}],TableHeadings-> {Automatic,None}] Out[]= 1 False {1} 2 True {1, 2} 3 False {3} 4 True {3, 4} 5 False {5} 6 False {6} 7 True {6, 7} 8 True {6, 7, 8} 9 True {6, 7, 8, 9} 10 False {10} 11 True {10, 11}
- Follow-Ups:
- Re: list/sequence problem: a 'keep' list to a list of
- From: Miles Rains <mileskrains@gmail.com>
- Re: list/sequence problem: a 'keep' list to a list of
- From: DrMajorBob <btreat1@austin.rr.com>
- Re: list/sequence problem: a 'keep' list to a list of
- From: DrMajorBob <btreat1@austin.rr.com>
- Re: list/sequence problem: a 'keep' list to a list of