1
$\begingroup$

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?

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

1 Answer 1

1
$\begingroup$

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}}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.