MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Better way to write this

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85083] Re: Better way to write this
  • From: "Steve Luttrell" <steve at _removemefirst_luttrell.org.uk>
  • Date: Sun, 27 Jan 2008 05:49:15 -0500 (EST)
  • References: <fnet45$id5$1@smc.vnet.net>

Tally gives the number of times each element of a list occurs, then pick out 
the cases that occur only once.

Here is an example:

data = RandomInteger[{1, 100}, {250}];
Cases[Tally[data], {x_, 1} :> x]

Stephen Luttrell
West malvern, UK

"Louis Theran" <theran at gmail.com> wrote in message 
news:fnet45$id5$1 at smc.vnet.net...
>I have the following function that takes as its input a number of
> lists and returns the elements in each of them that appear exactly
> once:
>
> SpecialElements[lists:_List..]:=
> Module[{l,n,Sower,Reaper},
> l = {lists}; n = Length[l];
> Sower[l_,{idx_}]:= Sow[idx,{#}] & /@ l;
> Reaper[val_,{place_}] := Sow[val,place];
> Reaper[val_,x_]:= Null;
> Reap[Reap[MapIndexed[Sower, l],_,Reaper],Range[n]][[2]]]
>
> This works pretty well, but since I am using it on rather large
> inputs, I was wondering if there is a faster way to implement it than
> Reap/Sow, which is sort of counting in unary.
>
> ^L
> 



  • Prev by Date: Re: Better way to write this
  • Next by Date: Re: Converting Radians into Degrees into Mathematica 6.01
  • Previous by thread: Re: Better way to write this
  • Next by thread: Re: Better way to write this