MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: DeleteCases

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98171] Re: DeleteCases
  • From: Pillsy <pillsbury at gmail.com>
  • Date: Wed, 1 Apr 2009 05:56:48 -0500 (EST)
  • References: <gqsn69$3qp$1@smc.vnet.net>

On Mar 31, 5:19 am, Filippo Miatto <sottosupr... at gmail.com> wrote:
> 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?

Here's one way of doing it, which depends on the function
DeleteDuplicates[] from Mathematica 7. If you don't have Mathematica
7, things get a little trickier, I'm afraid, though if you at least
have 6, you can fake it by defining,

DeleteDuplicates[list_, test_] := First /@ Tally[list, test]

Then you just need to make the test treat both its arguments as the
same if they have the same elements in any order, which you can do
with Sort[], like so:

deleteOrderlessDuplicates[list_] := DeleteDuplicates[list,
     Sort[#1] === Sort[#2] & ]

Cheers,
Pillsy


  • Prev by Date: Re: DeleteCases
  • Next by Date: Re: Using manipulate in two cells in one note book crashes my computer.
  • Previous by thread: Re: Re: DeleteCases
  • Next by thread: Re: DeleteCases