From: George on
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

From: Bob Hanlon on

data = RandomInteger[{0, 9}, 20]

{5,5,9,2,6,5,3,9,1,6,1,0,9,6,4,5,8,6,7,5}

Select[Union[data], Count[data, #] == 1 &]

{0,2,3,4,7,8}

Cases[Union[data], _?(Count[data, #] == 1 &)]

{0,2,3,4,7,8}

DeleteCases[Union[data], _?(Count[data, #] > 1 &)]

{0,2,3,4,7,8}

Cases[{#, Count[data, #]} & /@ Union[data], {x_, 1} -> x]

{0,2,3,4,7,8}


Bob Hanlon

---- George <gtatishvili(a)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



From: DrMajorBob on
list = RandomInteger[{0, 5}, 7]

{0, 0, 0, 4, 5, 2, 3}

Cases[Tally[list], {x_, 1} :> x]

{4, 5, 2, 3}

Bobby

On Sun, 10 Jan 2010 02:28:47 -0600, George <gtatishvili(a)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
>


--
DrMajorBob(a)yahoo.com

From: Murray Eisenberg on
Here's one way, via an example:

lis = RandomChoice[Characters["abcdefghijklmnopqrstuvwxyz"], 50];

Select[Union[lis], Count[lis, #] == 2 &]

Your results will vary according to what RandomChoice gives you. But the
code does exactly what you asked: it selects (Select) from the unique
elements of the list (Union[lis]) those elements for which the Count of
their appearances in the list is 2.

I make no claims for the efficiency of the code. That may depend upon
the length and perhaps even the elements of your list, among other things.

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?
>
> Thks much
> George
>

--
Murray Eisenberg murray(a)math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

From: Peter Pein on
George schrieb:
> 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
>

Hi George,

calculating some data:

SeedRandom[5];
theList=Insert[RandomChoice[#/Tr[#]&[1/#^4]->#,{10^6}]&[Range[100]],{a,b,a,c},123456];

to preserve the order of occurrance, I would use:

Reap[
NestWhile[
(If[FreeQ[##1],
Sow[#2];#1,
DeleteCases[##1]]&)@@{Rest[#1],First[#1]}&,
theList,
#1=!={}&]
][[2,1]]

which gives: {26,29,35,{a,b,a,c},40,60,28,34,33,31,32}

If you want sorted results, use the simple (and fast)

Cases[Split[Sort[theList]],{x_}:>x]

---> {26,28,29,31,32,33,34,35,40,60,{a,b,a,c}}


HTH,
Peter