Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14881

Re: Removing list elements in x by list y

From Dana DeLouis <dana01@icloud.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Removing list elements in x by list y
Date 2013-06-15 08:18 +0000
Message-ID <kph80r$2fa$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


> I wish to "subtract" y from x, i.e. remove exactly the elements in x

Hello.  I may be wrong, but if you have 10 each of everything, and wanted to subtract 8 of each item, you should be left with 2 items of each.

x=Table[{a,b,c,d},{10}]//Flatten//Sort;
y=Table[{a,b,c,d},{8}]//Flatten//Sort;

Select[x,FreeQ[y,#]&]
{}
Cases[x,_?(FreeQ[y,#]&)]
{}
Pick[x,FreeQ[y,#]&/@x]
{}
Delete[x,Flatten[Map[Position[x,#]&,y],1]]
{}
x/.a_/;MemberQ[y,a]->Sequence[]
{}
Delete[x,Flatten[Position[x,#]&/@y,1]]
{}
DeleteCases[x,Alternatives@@y]
{}
Select[x,!MemberQ[y,#]&]
{}

I believe the answer should be:

Fold[DeleteCases[#1,#2,1,1]&,x,y]
{a,a,b,b,c,c,d,d}


















On Thursday, June 13, 2013 2:31:35 AM UTC-4, Dr. Wolfgang Hintze 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


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Removing list elements in x by list y Dana DeLouis <dana01@icloud.com> - 2013-06-15 08:18 +0000

csiph-web