3
$\begingroup$

I am trying to use DeleteCase function but I don't know how to implement it in the way I need.

I have a list of sublists of numbers, for example:

{{1,1,1,1},{1,1,1,2},{4,2,5,1},{5,3,2,4}}

and I want to do is to delete all the sublists that contains an element greater than $4$.

The result would be like this:

{{1,1,1,1},{1,1,1,2}}

I am also avoiding loops or recursion.

$\endgroup$
  • $\begingroup$ Look up Condition and Max. $\endgroup$ – Szabolcs Oct 2 '17 at 16:37
3
$\begingroup$
 list = {{1, 1, 1, 1}, {1, 1, 1, 2}, {4, 2, 5, 1}, {5, 3, 2, 4}};    
 Select[list, Max[##] < 4 &]
$\endgroup$
3
$\begingroup$
lst = {{1, 1, 1, 1}, {1, 1, 1, 2}, {4, 2, 5, 1}, {5, 3, 2, 4}}; 

Pick[#, UnitStep[4 - Max /@ # ], 1] & @ lst
Pick[#, LessEqualThan[4] /@ Max /@ #]& @ lst 
Cases[lst, _?(Max @ # <= 4 &)]
DeleteCases[lst, _?(Max @ # > 4 &)]
Select[lst, Composition[LessEqualThan[4], Max]]

all give

{{1, 1, 1, 1}, {1, 1, 1, 2}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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