MathGroup Archive 2012

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

Search the Archive

Custom sorting via ordering list

  • To: mathgroup at
  • Subject: [mg124158] Custom sorting via ordering list
  • From: Chris Young <cy56 at>
  • Date: Wed, 11 Jan 2012 04:24:43 -0500 (EST)
  • Delivered-to:

Don't really need the matrix I had in my previous post, just the sort 
specification. All the upper-triangular matrix did was to ensure there 
was a less-than-or-equal relation, and we're taking care of that by 
simply testing pairs of elements to make sure they're in the same 
left-to-right order as they are in the "sorted" list we specify in the 
in_order function.

In[839]:= in\[HorizontalLine]order2[e1_, e2_] :=
  sorted = {1, 2, a, b, A, B};

  Position[sorted, e1][[1, 1]] <= Position[sorted, e2][[1, 1]]

In[840]:= Sort[list, {e1, e2} \[Function] in\[HorizontalLine]order2[e1, e2]]

Out[840]= {1, 2, a, b, A, B}

In[841]:= Sort[{B, a, 1, b, b, 1}, {e1, e2} \[Function]
  in\[HorizontalLine]order2[e1, e2]]

Out[841]= {1, 1, a, b, b, B}

  • Prev by Date: Re: Is it possible to flatten hash table?
  • Next by Date: Re: Plotting an Array of Vectors
  • Previous by thread: FullSimplify issue
  • Next by thread: Tick marks don't scale proportionally with other elements of the