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


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

Re: Removing list elements in x by list y

Started byDana DeLouis <dana01@icloud.com>
First post2013-06-15 08:18 +0000
Last post2013-06-15 08:18 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

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

#14881 — Re: Removing list elements in x by list y

FromDana DeLouis <dana01@icloud.com>
Date2013-06-15 08:18 +0000
SubjectRe: Removing list elements in x by list y
Message-ID<kph80r$2fa$1@smc.vnet.net>
> 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


[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web