Re: DeleteCases
- To: mathgroup at smc.vnet.net
- Subject: [mg98207] Re: DeleteCases
- From: "andre.robin3" <andre.robin3 at wanadoo.fr>
- Date: Thu, 2 Apr 2009 04:49:17 -0500 (EST)
- References: <gqsn69$3qp$1@smc.vnet.net>
1) A solution for the first problem : data00 = {{0, 0, 1, 1}, {0, 0, 2, 2}, {0, 0, 3, 3}, {1, 1, 0, 0}, {1, 1, 2, 2}, {1, 1, 3, 3}, {2, 2, 0, 0}, {2, 2, 1, 1}, {2, 2, 3, 3}, {3, 3, 0, 0}, {3, 3, 1, 1}, {3, 3, 2, 2}}; data00 //. {x1___, a : {a1_, a1_, b1_, b1_}, x2___, {b1_, b1_, a1_, a1_}, x3___} -> {x1, a, x2, x3} It returns :{{0, 0, 1, 1}, {0, 0, 2, 2}, {0, 0, 3, 3}, {1, 1, 2, 2}, {1, 1, 3, 3}, {2, 2, 3, 3}} as you want. 2) For the more general second point : data01 = {{a, b, c, d}, {b, a, c, d}, {a, b, d, c}}; testQ[a_, b_] := (Sort[a] === Sort[b]) (* put here any relation you want, this one fuullfills your need, so far i understand it *) data01 //. ({x1___, a : {_, _, _, _}, x2___, b : {_, _, _, _}, x3___} /; testQ[a, b]) -> {x1, a, x2, x3} It returns : {{a, b, c, d}} as you want, I think. It works with data00 too. The key command is "//." (alias "PeplaceAll[ ]") or anything of the family "*Replace*" (Replace,RepladeRepeated ..) The solutions I suggest here are slow (not to use on big data sets). "Filippo Miatto" <sottosupremo at gmail.com> a écrit dans le message de news: gqsn69$3qp$1 at smc.vnet.net... > Dear all, > Given this example list: > > {{0, 0, 1, 1}, {0, 0, 2, 2}, {0, 0, 3, 3}, {1, 1, 0, 0}, {1, 1, 2, 2}, > {1, 1, 3, 3}, {2, 2, 0, 0}, {2, 2, 1, 1}, {2, 2, 3, 3}, {3, 3, 0, 0}, > {3, 3, 1, 1}, {3, 3, 2, 2}} > > I need the elements {a,a,b,b} and {b,b,a,a} to be the same, i.e. i > want to delete one of the two occurrences from the list. (or all but > one if the condition is more complicated, say {a,b,c,d} and {b,a,c,d} > or {a,b,c,d} and {a,b,d,c}) > How can i do that? Can i use DeleteCases? if so, what conditional > should I use to compare different elements in the list? > I tried without success for all the night.. (it's 6.15AM now!) > Thank you, > > Filippo >