For example, we have a list ={1,2,3,4,5,6}
, we can use Cases[list,x_/; 3<x<10]
to pick up {4,5,6}
.
What if we are dealing with a nested list for example : list2={{0.1,0.2},{0.1,0.2},{0.2,0.3},{0.3,0.4}}
;
Shall I use something like Cases[list2,{x_,y_}/;0<x+y<0.5]
to pick up {0.1,0.2}
in this case?
Select
seems more natural thanCases
$\endgroup$Cases
will match only at the top level:Cases[{{1},{2},{3}}, _Integer]
will return{}
because the elements at the top level would match{_Integer}
.Cases[{{1}, {2}, {3}}, _Integer, 2]
, however, returns{1,2,3}
. Look at the documentation forCases
, and look at the third argument in particular. $\endgroup$