Re: DeleteCases

• To: mathgroup at smc.vnet.net
• Subject: [mg98176] Re: DeleteCases
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Wed, 1 Apr 2009 05:57:45 -0500 (EST)

```On 3/31/09 at 4:19 AM, sottosupremo at gmail.com (Filippo Miatto) wrote:

>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?

Given you are treating {a,a,b,b} the same as {b,b,a,a} I assume
it doesn't matter which is saved. That is sorting each to put
them into a standard I assume is acceptable. So,

In[1]:= data = {{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}};

In[2]:= Union[Sort /@ data]

Out[2]= {{0, 0, 1, 1}, {0, 0, 2, 2}, {0, 0, 3, 3}, {1, 1, 2, 2}, {1,
1, 3, 3}, {2, 2, 3, 3}}

does the trick.

If the list has elements with a pattern different than {a,a,b,b}
that you want to preserve ordered as they are then

Union[data/.{a_,a_,b_,b_}:>Sort[{a,a,b,b}]

should work. And if you need to preserve the order in which each
sublist appears, use DeleteDuplicates instead of Union

```

• Prev by Date: Re: Using manipulate in two cells in one note book crashes my computer.
• Next by Date: Re: Integrating package documentation with the documentation center
• Previous by thread: Re: DeleteCases
• Next by thread: Re: DeleteCases