Cases for nested lists
lst = {{{x1, y1}, {{a1, 1}, {c1, d1}}},
{{x2, y2}, {{a2, -1}, {c2, d2}}},
{{x3, y3}, {{a3, 1}, {c3, d3}}},
{{x4, y4}, {{a4, -1}, {c4, d4}}}};
Cases[{_, {{_, _?Negative}, __List}}] @ lst
{{{x2, y2}, {{a2, -1}, {c2, d2}}}, {{x4, y4}, {{a4, -1}, {c4, d4}}}}
Select[#[[2, 1, 2]] < 0 &] @ lst
{{{x2, y2}, {{a2, -1}, {c2, d2}}}, {{x4, y4}, {{a4, -1}, {c4, d4}}}}
Pick [lst, Negative[lst[[All, 2, 1, 2]]]]
{{{x2, y2}, {{a2, -1}, {c2, d2}}}, {{x4, y4}, {{a4, -1}, {c4, d4}}}}
Not to take away from kglr’s wonderful answer, but using their defined example lst
, we can arrange a slightly more general application of Cases
:
Cases[a_:>a/;a[[2,1,2]]<0][lst]
Same output as kglr.
In this way, it is somewhat an amalgam of the methods shown by kglr. You’ll need to know the position of your value in advance, of course, and you can then designate the desired conditions.
What if you don’t know the position of the values that you want to satisfy the condition?
Try this:
Extract[List@*First/@Position[a_/;a<0][Last/@lst]][lst]
Same output.