Re: sort list
- To: mathgroup at smc.vnet.net
- Subject: [mg47249] Re: sort list
- From: adam.smith at hillsdale.edu (Adam Smith)
- Date: Thu, 1 Apr 2004 00:03:35 -0500 (EST)
- References: <c4be1n$702$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
This is probably not the most elegant but it works. In[1]:= mylist = {{something1,3},{something2,1},{something3,2}} Out[1]= {{something1,3},{something2,1},{something3,2}} In[2]:= newlist = Reverse/@mylist Out[2]= {{3,something1},{1,something2},{2,something3}} In[3]:= orderlist = Sort[newlist] Out[3]= {{1,something2},{2,something3},{3,something1}} In[4]:= finallist = Reverse/@orderlist Out[4]= {{something2,1},{something3,2},{something1,3}} Here one can do it on one line. In[5]:= Reverse/@Sort[Reverse/@mylist] Out[5]= {{something2,1},{something3,2},{something1,3}} Adam Smith 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