MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sort pairs

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: sort pairs
  • From: keiper
  • Date: Thu, 11 Nov 93 07:01:32 -0600

	> How can I sort pairs of values -- basing the sort on the
	> first value and then break ties on the second value in
	> the pair.

Just use Sort[ ].  That is what it does.  For example:

In[5]:= data = Flatten[Table[{j, 4-i}, {i, 3}, {j, 3}], 1]

Out[5]= {{1, 3}, {2, 3}, {3, 3}, {1, 2}, {2, 2}, {3, 2}, {1, 1}, {2, 1}, 
 
>    {3, 1}}

In[6]:= Sort[%]

Out[6]= {{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, 
 
>    {3, 3}}


Jerry B. Keiper
keiper at wri.com
Wolfram Research, Inc.






  • Prev by Date: notation
  • Next by Date: courses
  • Previous by thread: notation
  • Next by thread: sort pairs