Re: Group and Replace itens sequence in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg127821] Re: Group and Replace itens sequence in a list
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Fri, 24 Aug 2012 05:04:52 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20120823065202.F18956843@smc.vnet.net>
Clear[f] f[list_?VectorQ] := Cases[ (list //. {s___, a, b, a, r___} -> {{s}, {r}}) /. {} -> Sequence[], _?VectorQ, Infinity] f[{1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12}] {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}} f[{a, b, a, 1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12}] {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}} f[{1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12, a, b, a}] {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}} f[{a, b, a, 1, 2, 3, a, b, a, 4, 5, 6, a, b, c, 7, 8, 9, a, b, a, 10, 11, 12, a, b, a}] {{1, 2, 3}, {4, 5, 6, a, b, c, 7, 8, 9}, {10, 11, 12}} Bob Hanlon On Thu, Aug 23, 2012 at 2:52 AM, Murta <rodrigomurtax at gmail.com> wrote: > Hi All > > I have a simple problem that is: > > l={1,2,3,a,b,a,4,5,6,a,b,c,7,8,9,a,b,a,10,11,12} > > I want to replace all a,b,a sequence by X to get: > > l={1,2,3,X,4,5,6,a,b,7,8,9,X,10,11,12} > > Then I want to group it by X intervals as > l={{1,2,3},{4,5,6,a,b,7,8,9},{10,11,12}} > > If I don't need to put the intermediate X, even better! > I think the with pattern, RaplaceAll and DeleteCases I can do It. Some clue? > Tks > Murta > > >
- Follow-Ups:
- Re: Group and Replace itens sequence in a list
- From: Murta <rodrigomurtax@gmail.com>
- Re: Group and Replace itens sequence in a list
- From: Fred Simons <f.h.simons@tue.nl>
- Re: Group and Replace itens sequence in a list
- References:
- Group and Replace itens sequence in a list
- From: Murta <rodrigomurtax@gmail.com>
- Group and Replace itens sequence in a list