Re: lists of pairs
- To: mathgroup at smc.vnet.net
- Subject: [mg8512] Re: lists of pairs
- From: tburton at cts.com (Tom Burton)
- Date: Thu, 4 Sep 1997 02:20:02 -0400
- Organization: Brahea Consulting
- Sender: owner-wri-mathgroup at wolfram.com
On 2 Sep 1997 18:09:13 -0400, in comp.soft-sys.math.mathematica you wrote: > >Hi all, I have a problem in discarding duplicates from a list of integer >pairs, where if pairs of the form {a, b} and {b,a} exist in the list, I >wish to discard (or select) only one, it doesn't matter which... Russel, Since you don't care which, why not sort the lists (at both levels) first, and then check for adjacent identical lists. In[6]:=3D edges=3DTable[{i,j},{i,300},{j,300}]; In[9]:=3D Timing[edges1=3DSort[Sort/@edges];] Out[9]=3D {0.33 Second,Null} In[10]:=3D Timing[edges2=3Dedges1//.{a___,b_,b_,c___}->{a,b,c};] Out[10]=3D {38.89 Second,Null} As you can see, the sorting time is negligible. Perhaps there is a faster way to reduce identical adjacent pairs. There's been a lot of discussion on and around this subject in this group and elsewhere. Tom Burton