I have a very long nested list. Here is a short example:
list = {{1.2, {1, 1, 1, 1}, {2, 2, 2}}, {0.9, {3, 3, 3, 3}, {4, 4, 4}}, {1.4, {4, 4, 4, 4}, {5, 5, 5}}}
Now I want to cancel all entries if the first entry of each part of the list (list[[i]]
) is > 1. So that the new list would only consist of the second part of list (list[[2]]
)
newlist = {0.9, {3, 3, 3, 3}, {4, 4, 4}}
I have already tried my luck with Position
and Delete
, but with no success.
Thanks a lot for your help!
Cases[list, {x_?NumericQ, a__} /; x <= 1 -> {x, a}]
$\endgroup$Pick
, e.g. my own answers to (900) and (30155) $\endgroup$Cases[list, {x_, a__} /; x <= 1]
. Also don't forget to use:>
with named patterns! $\endgroup$list
, it should therefore be{{0.9, {3, 3, 3, 3}, {4, 4, 4}}}
(note the extra{}
) -- Unless you know that only one item will be selected. $\endgroup$