Re: Generalizing Complement to handle multiple occurrences of elements

• To: mathgroup at smc.vnet.net
• Subject: [mg112443] Re: Generalizing Complement to handle multiple occurrences of elements
• From: Yves Klett <yves.klett at googlemail.com>
• Date: Wed, 15 Sep 2010 20:02:57 -0400 (EDT)
• References: <i6q0ml\$l7c\$1@smc.vnet.net>

```Hi,

a = {1, 2, 2, 3, 4, 4, 4, 4};
b = {3, 5, 7};

Cases[a, Alternatives @@ Complement[a, b]]

{1, 2, 2, 4, 4, 4, 4}

Predictably, there will be faster solutions than using Cases though.

Regards,
Yves

Am 15.09.2010 10:38, schrieb Mark Coleman:
> 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
>

```

• Prev by Date: Re: Extracting some elements, members of another list
• Next by Date: Re: Generalizing Complement to handle multiple occurrences
• Previous by thread: Re: Generalizing Complement to handle multiple occurrences
• Next by thread: Re: Generalizing Complement to handle multiple occurrences of elements