Better way to write this
- To: mathgroup at smc.vnet.net
- Subject: [mg85058] Better way to write this
- From: Louis Theran <theran at gmail.com>
- Date: Sat, 26 Jan 2008 05:00:47 -0500 (EST)
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
- Follow-Ups:
- Re: Better way to write this
- From: Murray Eisenberg <murray@math.umass.edu>
- Re: Better way to write this