2
$\begingroup$

Suppose we have a list {a, b, c} and a mask {1, 0, 1} (or {True, False, True}). And we want to apply this mask to a list -- we want to keep elements that correspond to 1 or True in the mask and to remove elements that correspond to 0 or False.

I found only Select and Cases functions, but they seem to work only with patterns and functional criterion.

So what will be the good solution?

$\endgroup$
7
$\begingroup$

Try

Pick[{a, b, c}, {True, False, True}]
(*{a,c}*)

or

Pick[{a, b, c}, {1,0,1},1]
$\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.