Re: Occurrences in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg106368] Re: Occurrences in Mathematica
- From: Helen Read <hpr at together.net>
- Date: Mon, 11 Jan 2010 05:27:08 -0500 (EST)
- References: <hic33o$59f$1@smc.vnet.net>
- Reply-to: HPR <read at math.uvm.edu>
On 1/10/2010 3:28 AM, George wrote: > Hi, > > I have a very big list of elements and I need Mathematica to give me > only those elements which occure only once... > > Could anybody advise me please how to write the code for that? Here's one way. First, make a list: list = RandomInteger[100, 75] Now select the elements that appear exactly once in the list: Select[list, Count[list, #] == 1 &] For a very large list, you might first use Union to find all elements that occur at least once in the original list. Then test each element of the union (instead of the original list with all the duplicates) and select those that occur exactly once in the original list. union=Union[list] Select[union, Count[list, #] == 1 &] BTW, it is helpful when posing questions to include a specific example (copy/paste as Input Text) so that folks replying know what you are talking about and don't have to make up their own example. -- Helen Read University of Vermont