Re: sort list
- To: mathgroup at smc.vnet.net
- Subject: [mg47237] Re: sort list
- From: "Bo Le" <bole79 at email.si>
- Date: Wed, 31 Mar 2004 02:59:33 -0500 (EST)
- References: <c4be1n$702$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Helo, Sort is the solution to your problem: In[1]:= testList=Module[{s="borut"}, Transpose[ {Characters[s],ToCharacterCode[s]-96} ] ] Out[1]= {{b,2},{o,15},{r,18},{u,21},{t,20}} In[2]:= Sort[testList,(#1[[2]]<#2[[2]])&] Out[2]= {{b,2},{o,15},{r,18},{t,20},{u,21}} I built the test list first and then sorted it accordig to the criteria, which is written as a pure function that compares the second elements ([[2]]) of each two sequential pairs (left pair = #1, right one = #2). The list is internally changing until the changing stops and - voila, the sorted list is returned. Helps? Borut Levart Slovenia "Guibout" <guibout at ifrance.com> wrote in message news:c4be1n$702$1 at smc.vnet.net... > Hi, > I have a list of the form > {{something1,x1},{something2,x2},{something3,x3}} where x1,x2, x3 are > numbers. I want to sort this list with respect to xi. In other word if > x2<x3<x1 I want Mathematica to produce: > {{something2,x2},{something3,x3},{something1,x1}} > Thanks for your help > Vincent >