Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Removing list elements in x by list y

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131136] Re: Removing list elements in x by list y
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Fri, 14 Jun 2013 04:57:55 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20130613063635.3F7206A2A@smc.vnet.net>

x = {u, v, w, w, d};
y = {u, d};


Select[x, FreeQ[y, #] &]


{v, w, w}


Cases[x, _?(FreeQ[y, #] &)]


{v, w, w}


DeleteCases[x, _?(MemberQ[y, #] &)]


{v, w, w}


Pick[x, FreeQ[y, #] & /@ x]


{v, w, w}



Bob Hanlon


On Thu, Jun 13, 2013 at 2:36 AM, Dr. Wolfgang Hintze <weh at snafu.de> wrote:

> I have simple question.
>
> Given two lists
>
> x = {u, v, w, w, d};
> y = {u, d};
>
> I wish to "subtract" y from x, i.e. remove exactly the elements in x
> which belong to y giving
>
> x "-" y = {v,w,w}
>
> Complement[] gives instead {v,w}.
> Note that we are talking about lists rather than sets.
>
> I'm sure there is a simple standard command, but I can't find it.
> Can you?
>
> Regards,
> Wolfgang
>
>


  • Prev by Date: Re: Position
  • Next by Date: Re: Position
  • Previous by thread: Removing list elements in x by list y
  • Next by thread: Re: Removing list elements in x by list y