MathGroup Archive 2003

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

Search the Archive

RE: Delete cases nested list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42782] RE: [mg42767] Delete cases nested list
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 25 Jul 2003 11:54:51 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: The Leddons [mailto:jleddon1 at comcast.net]
To: mathgroup at smc.vnet.net
>Sent: Friday, July 25, 2003 11:08 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg42782] [mg42767] Delete cases nested list
>
>
>
>Hello,
>I have 2 lists, lis1 and lis2, I want to compare to each other for the 
>purpose of deleting sublists of lis1 that have elements matching those 
>in lis2. I tried this:
>
>lis1 = {{2, 3, 4, 5, 6, 7, C1}, {2, 3, 4, 5, 6, 71, B6}, {1, 2, 3, 4, 
>5, 6, C11}, {4, 5, 6, 7, 8, 7, C4}, {23, 3, 2, 5, 6, 7, M2}, {2, 3, 9, 
>5, 6, 71, B3}};
>
>lis2 = {C11, B6, B3};
>
>lis3 = DeleteCases[lis1, {x_lis2}, {2}]
>
>What I want is:
>
>lis3 = {{2, 3, 4, 5, 6, 7, C1}, {4, 5, 6, 7, 8, 7, C4}, {23, 
>3, 2, 5, 6, 7, M2}};
>
>However, this didn't work. Note that I want to delete all 
>cases containing B.
>
>Any ideas?
>
>Cheers,
>
>Debbie
>
>
>
>

A few suggestions:

DeleteCases[lis1, Alternatives @@ ({___, #} &) /@ lis2, {1}]

DeleteCases[lis1, {___, Alternatives @@ lis2}, {1}]

DeleteCases[lis1, {_, _, _, _, _, _, Alternatives @@ lis2}, {1}]

Select[lis1, FreeQ[#, Alternatives @@ lis2, {1}] &]

Select[lis1, FreeQ[Last[#], Alternatives @@ lis2, {0}] &]

Select[lis1, 
  And @@ With[{tag = Last[#], lis2 = lis2}, 
        Thread[Unevaluated[UnsameQ[tag, lis2]]]] &]


They are not all equivalent, other patterns are possible too, 
depending on more precise specification of input.


--
Hartmut Wolf


  • Prev by Date: Re: Delete cases nested list
  • Next by Date: Re: webMathematica-Mathematica communication problem
  • Previous by thread: Re: Delete cases nested list
  • Next by thread: Re: Delete cases nested list