2
$\begingroup$

I'd like to know how to define logical conditions to manipulate them. For example, say I have a list list of pairs of numbers, and I want to Select those which satisfy some condition

cond = #[[1]] > 0 &;

Then I just have to evaluate Select[list, cond]and it works. But if I have several conditions

cond1 = #[[1]] > 0 &; cond2 = #[[2]] > 0 &;

then both Select[list, cond1 && cond2] and Select[list, cond1 || cond2] always give an empty list. How do I have to combine the conditions inside Select[ ] so that it understands the logical connection between them ( AND or OR)?

$\endgroup$
1
$\begingroup$

You could do:

Select[list, Through @* And[cond1, cond2]]

For example:

Select[Range[10], Through @* And[PrimeQ,EvenQ]]

{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.