Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7598 > unrolled thread

SortBy for multiple key sorts

Started byChris Young <cy56@comcast.net>
First post2012-01-06 09:17 +0000
Last post2012-01-06 09:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  SortBy for multiple key sorts Chris Young <cy56@comcast.net> - 2012-01-06 09:17 +0000

#7598 — SortBy for multiple key sorts

FromChris Young <cy56@comcast.net>
Date2012-01-06 09:17 +0000
SubjectSortBy for multiple key sorts
Message-ID<je6e7e$q8a$1@smc.vnet.net>
Finally figured out a reasonably simple way to sort by two keys, in
this case by the y-coordinates, and then within that sorting, by
x-coordinates. This is just a standard way to sort points: from bottom
to top in rows, and within each row from left to right. Why on earth
can't Sort take a list of ordering functions so that the same thing can
be done there?

In[1200]:= pts =
 {
  {0, 2}, {1, 2}, {2, 2},
  {4, 1}, {3, 1}, {6, 1}, {5, 1},
  {7, 0}, {-1, 0}
  }

In[1206]:= sortByYthenX = SortBy[pts, {Min[#[[2]]] &, Min[#[[1]]] &}]

Out[1206]= {{-1, 0}, {7, 0}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {0,
  2}, {1, 2}, {2, 2}}

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web