# Picking out elements from a multi-level list

I have the following problem that is giving me headaches: I have a list with the elements in the following form:

{x,{{a1,b1},{a2,b2},{a3,b3}}}


I would like to select all the elements in this list that satisfy the following rules simultaneously:

1. x<0
2. ai x bi <0, where i is 1,2 or 3

I tried to use Select but I am having trouble getting it to apply the second condition.

## 1 Answer

Generating some toy data and testing:

ab = RandomInteger[{-10, 10}, {10, 3, 2}];
xs = RandomInteger[{-10, 10}, 10];
dat = Thread[{xs, ab}]
Select[dat, And[#[] < 0, AnyTrue[#[], Times @@ # < 0 &]] &] • Sorry but maybe I didn't explain it properly: the result I am looking for is: if a2 x b2 <0 then the result of Select should be {x,{a2,b2}}. Does it make sense? – lucian Nov 8 '19 at 11:31
• @lucian it would be helpful if you provided a toy example. Otherwise you can modify code and assess response. Starting with small test case is useful. I suggest also looking at AllTrue, AnyTrue etc in the documentation. – ubpdqn Nov 8 '19 at 11:35
• your toy data is exactly like my data. What I need to do is turn the list with elements in the form {x,{{a1,b1},{a2,b2},{a3,b3}} into a list (it can be smaller than the original list!) with elements {x,{a,b}} where the pair {a,b} is one of the three pairs in the original list such that a b<0 – lucian Nov 8 '19 at 11:40
• @lucian with respect that is somewhat different to OP. I encourage you to try, provide an example, esp given there may be more than one pair that meets your criteria and therefore require some mechanism for choosing be it something well defined or random. – ubpdqn Nov 8 '19 at 11:43
• you are probably right! I need to rethink my problem. Thank you! – lucian Nov 8 '19 at 11:45