MathGroup Archive 2007

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

Search the Archive

Re: Sort problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81721] Re: Sort problem
  • From: yatesd at mac.com
  • Date: Tue, 2 Oct 2007 05:37:42 -0400 (EDT)
  • References: <fdqd33$n6m$1@smc.vnet.net>

Sort by default will put the elements of the list into canonical
order, which appears to be what you want. Namely:

In[6]:= Sort[{{r, 2}, {a, 3}, {x, 4}}]

Out[6]= {{a, 3}, {r, 2}, {x, 4}}

This is equivalent functionally to Sort[{{r, 2}, {a, 3}, {x, 4}},
OrderedQ[{#1, #2}] &] although supplying your own sort function
usually has a drastic impact on performance (noticeable on large
lists).

#1[[1]] < #2[[1]] & did not work because the 'Less' function (<) is
not defined for strings. You can see this by trying to evaluate:

In[9]:= {a, 3}[[1]] < {r, 2}[[1]]

Out[9]= a < r

Regards,

Derek



  • Prev by Date: Re: Other bug in ContourPlot
  • Next by Date: NMinimize
  • Previous by thread: Re: Sort problem
  • Next by thread: Re: Sort problem