# Sorting pairs of approximate numbers

In an ideal world I would have:

list1 = {{2, 0}, {2, -1}, {2, 0}, {2, -1}};
Sort[list1]


{{2, -1}, {2, -1}, {2, 0}, {2, 0}}

while in the real world I have:

list2 = {{1.999999927261, 2.33473182872375 10^-8},
{2.00000002055154, -0.99999987168595},
{2.00000013088255, -4.79449275287154 10^-8},
{2.00000013921051, -1.00000012791526}};
Sort[list2]


{{2., 2.33473 10^-8}, {2., -1.}, {2., -4.79449 10^-8}, {2., -1.}}

So, the question is: how to get the first sort with the second list?

{{2., -1.}, {2., -1.}, {2., -4.79449 10^-8}, {2., 2.33473 10^-8}}

One idea would be to consider the integer part of such numbers, but does that make sense as what? Otherwise, what would you suggest? Thank you!

one option could be

list2 = {{1.999999927261,
2.33473182872375 10^-8}, {2.00000002055154,-0.99999987168595},
{2.00000013088255, -4.79449275287154 10^-8}, {2.00000013921051,
-1.00000012791526}}

Sort[list2, (#1[[1]] <= #2[[1]] && #1[[2]] <= #2[[2]]) &]


Alternatively

SortBy[list2, Last]
(*{{2., -1.}, {2., -1.}, {2., -4.79449*10^-8}, {2.,2.33473*10^-8}}*)

• +1 If there are multiple clusters, broaden this to Flatten[SortBy[#, Last] & /@ GatherBy[list2, Round[#[[1]]] &], 1] Commented Feb 21, 2022 at 15:46