# Merging two rows with rounding their first elemnts

Mathematica shows my data in the below style:

  lst={....
{-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}},
{-0.410927, {{9, 14}, {10, 14}, {13, 7}, {13, 8}}}
.....}


As I copy the first -0.410927 in another cell, I saw that it is really -0.41092720756334744 and for the second -0.410927, I noticed that it is -0.4109272075633472 in fact. Regards to the other rows in the above and the below positions of these two shown rows, which are presented by ...., how I merge such two rows and have a result as

output=lst={....
{-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}, {9, 14}, {10, 14}, {13, 7}, {13, 8}}}
.....}


In fact, there is no any differences between two -0.410927for more digits than 3.

I have to apply this procedure for other rows considering this fact that all elements have just 3 digits for being important. For instance 1.34267 is not different from 1.34311.

How can I help Mathematica to merge multi rows with very similar first elements. The similarity is gained after rounding values up to 3 digits.

lst = { {-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}},
{-0.41, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}},
{-0.45123, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}},
{-0.410927, {{9, 14}, {10, 14}, {13, 7}, {13, 8}}}};

Values@GroupBy[lst,  Round[First@#, .001] &, {#[[1, 1]], Join @@ #[[All, 2]]} &]


{{-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}, {9, 14}, {10,     14}, {13, 7}, {13, 8}}},
{-0.41, {{11, 16}, {12, 16}, {15,     5}, {15, 6}}},
{-0.45123, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}}}

Values@GroupBy[lst,  Round[First@#, .01] &, {#[[1, 1]], Join @@ #[[All, 2]]} &]


{{-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}, {11, 16}, {12, 16}, {15, 5}, {15, 6}, {9, 14}, {10, 14}, {13, 7}, {13, 8}}},
{-0.45123, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}}}

• Thankxx so much. But a problem: once I write the result as grouped[[1]] I reach {{-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}}, {-0.410927, {{9,14}, {10, 14}, {13, 7}, {13, 8}}}} this out put is not yet merged! – Inzo Babaria May 16 '19 at 21:24
• @Inzo, please see the updated version. – kglr May 16 '19 at 21:34
• Amazing and wonderful !!! – Inzo Babaria May 16 '19 at 23:49
lst={{-0.410927,{{11,16},{12,16},{15,5},{15,6}}},{-0.41,{{11,16},{12,16},{15,5},{15,6}}},{-0.45123,{{11,16},{12,16},{15,5},{15,6}}},{-0.410927,{{9,14},{10,14},{13,7},{13,8}}}};

{#[[1,1]],Flatten[#[[All,2]],1]}&/@Values[GroupBy[lst,SetPrecision[#[[1]],3]&]]


{{-0.410927, {{11, 16}, {12, 16}, {15, 5}, {15, 6}, {9, 14}, {10, 14}, {13, 7}, {13, 8}}}, {-0.41, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}}, {-0.45123, {{11, 16}, {12, 16}, {15, 5}, {15, 6}}}}