Re: Better way to write this
- To: mathgroup at smc.vnet.net
- Subject: [mg85075] Re: [mg85058] Better way to write this
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 27 Jan 2008 05:45:07 -0500 (EST)
- Reply-to: hanlonr at cox.net
Take a look at Tally data = Sort[Table[RandomInteger[50], {100}]] {0,1,1,1,1,2,2,4,4,5,5,7,7,7,8,8,8,10,10,10,10,11,11,12,12,12,13,14,14,16,16,\ 16,17,19,19,21,21,22,22,23,23,23,23,23,24,24,24,25,25,25,25,26,26,26,26,27,27,\ 27,28,28,28,29,30,30,31,31,33,34,34,35,36,37,38,38,39,40,40,41,41,41,42,42,42,\ 42,42,44,45,45,46,47,48,48,48,48,48,49,49,49,49,49} Cases[Tally[data], {x_, 1} -> x] {0,13,17,29,33,35,36,37,39,44,46,47} Bob Hanlon ---- Louis Theran <theran at gmail.com> wrote: > 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 >