Re: How to select unique elements in a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg8041] Re: [mg7953] How to select unique elements in a list?
- From: Fred Simons <wsgbfs at wsgbo02.win.tue.nl>
- Date: Sat, 2 Aug 1997 22:32:49 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Carl Woll came with the following solution of his problem:
Distinct[a_] := Select[Union[a],Count[a,#]===1&]
Here is another solution, a short and (for me) amusing oneliner:
Distinct2 = List @@ DeleteCases[ Times @@ #, _Power ]&
It is also faster:
test = Table[i[Random[Integer,1000]],{1000}];
In[9] := Distinct[test]; // Timing
Out[10] = {12.5586 Second,Null}
In[11] := Distinct2[test]; // Timing
Out[11] = {1.43735 Second, Null}
Fred Simons
Eindhoven University of Technology