MathGroup Archive 2010

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

Search the Archive

Re: Generalizing Complement to handle multiple occurrences of

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112453] Re: Generalizing Complement to handle multiple occurrences of
  • From: Peter Pein <petsie at dordos.net>
  • Date: Thu, 16 Sep 2010 05:58:46 -0400 (EDT)
  • References: <i6q0ml$l7c$1@smc.vnet.net>

Am Wed, 15 Sep 2010 08:38:45 +0000 (UTC)
schrieb Mark Coleman <markspcoleman at gmail.com>:

> Greetings,
>
> I'm wondering how one can efficiently generalize the built-in
> Complement function to return multiple occurrences of elements. For
> instance, the current version generates
>
> a={1,2,2,3,4,4,4,4}
> b={3,5,7}
>
> Complement[a,b]={1,2,4}
>
> I'm looking for a way to define
>
> myComplement[a,b]={1,2,2,4,4,4,4}
>
> My current code is very inefficient!
>
> Thanks,
>
> Mark
>



In[1]:= a={1,2,2,3,4,4,4,4};
b={3,5,7};
DeleteCases[a, Alternatives @@ b]

Out[3]= {1,2,2,4,4,4,4}

hth,
P=B2



  • Prev by Date: Re: Generalizing Complement to handle multiple occurrences of elements
  • Next by Date: Re: Generalizing Complement to handle multiple occurrences of elements
  • Previous by thread: Re: Datapoint label spacing
  • Next by thread: How to mimic the Bold menu command