MathGroup Archive 2010

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

Search the Archive

Re: Generalizing Complement to handle multiple occurrences of elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112456] Re: Generalizing Complement to handle multiple occurrences of elements
  • From: Helen Read <hpr at together.net>
  • Date: Thu, 16 Sep 2010 05:59:19 -0400 (EDT)
  • References: <i6q0ml$l7c$1@smc.vnet.net>
  • Reply-to: read at cems.uvm.edu

On 9/15/2010 4:38 AM, Mark Coleman wrote:
> 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
>

How about this:

Select[a, FreeQ[b, #] &]

--
Helen Read
University of Vermont




  • Prev by Date: books on matrix methods?
  • Next by Date: Datapoint label spacing
  • Previous by thread: Re: Generalizing Complement to handle multiple occurrences of elements
  • Next by thread: Re: Generalizing Complement to handle multiple occurrences of elements