Re: Occurrences in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg106403] Re: Occurrences in Mathematica
- From: Ray Koopman <koopman at sfu.ca>
- Date: Mon, 11 Jan 2010 18:52:45 -0500 (EST)
- References: <hic33o$59f$1@smc.vnet.net>
On Jan 10, 12:28 am, George <gtatishv... at gmail.com> 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?
>
> Thks much
> George
It takes longer for Cases to process the Tally result
than it takes Tally to generate it. Pick is faster.
In[1]:= Timing@Length[a = RandomInteger[999999,1*^6]]
Out[1]= {0.05,1000000}
In[2]:= Timing@Length[b = Tally@a]
Out[2]= {1.59,631912}
In[3]:= Timing@Length[c = Cases[b,{x_,1}:>x]]
Out[3]= {1.73,367228}
In[4]:= Timing@Length[d = Pick[Sequence@@Transpose@b,1]]
Out[4]= {0.5,367228}
In[5]:= c === d
Out[5]= True