Re: Generalizing Complement to handle multiple occurrences
- To: mathgroup at smc.vnet.net
- Subject: [mg112446] Re: Generalizing Complement to handle multiple occurrences
- From: "Niels R. Walet" <niels.walet at manchester.ac.uk>
- Date: Wed, 15 Sep 2010 20:03:29 -0400 (EDT)
- References: <201009150838.EAA21715@smc.vnet.net>
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 > > Stupid oneliner: c = a; Apply[(c = DeleteCases[c, #]) &, b] -- Prof. Niels R. Walet Phone: +44(0)1613063693 School of Physics and Astronomy Fax: +44(0)1613064303 The University of Manchester Mobile: +44(0)7905438934 Manchester, M13 9PL, UK room 7.7, Schuster Building email: Niels.Walet at manchester.ac.uk web: http://www.theory.physics.manchester.ac.uk/~mccsnrw
- References:
- Generalizing Complement to handle multiple occurrences of elements
- From: Mark Coleman <markspcoleman@gmail.com>
- Generalizing Complement to handle multiple occurrences of elements