# How to select in the following way?

Consider the following nested list:

fff = {{1, 2, {{1, 2}, {3, 4}, {19, 20}, {21, 22}}}, {2,
8, {{0.5, 3}, {1.4, 2}, {3, 13}, {2, 18}, {0.3, 19}, {20, 21}}}}


Each of the entries in list has the form:

{a,b,table}


I would like to remove table rows for which the first element is > 3, i.e. to obtain

fff' = {{1, 2, {{1, 2}, {3, 4}}}, {2,
8, {{0.5, 3}, {1.4, 2}, {3, 13}, {2, 18}, {0.3, 19}}}}


Is it possible with a help of one command such as Select?

• which the first element is <=3, I think you meant >3 there? Jun 24, 2022 at 12:01
• @Nasser : no, why? Jun 24, 2022 at 12:05
• Because that is what you show as your desired output? It has all entries where the first element which is >3 was removed? Jun 24, 2022 at 12:07
• Ah, yes, excuse me. You are correct. Jun 24, 2022 at 12:09

Using MapThread:

MapThread[Join, {#[[1 ;; 2]] & /@
fff, #[[All, 3, All]] &@fff /. {x_, y_} /; x > 3 -> Nothing}]


Using MapAt:

MapAt[If[First@# > 3, Nothing, #] &, fff, {All, 3, All}]


Using Select:

MapAt[Select[#, First@# <= 3 &] &, fff, {All, 3}]


Result:

{{1, 2, {1, 2}, {3, 4}}, {2, 8, {0.5, 3}, {1.4, 2}, {3, 13}, {2, 18}, {0.3, 19}}}