2
$\begingroup$

Suppose I have the following list :

l={{a, b, d}, {a, v}, {b, c, d}}

I want to delete those elements that contain the letter a such that I get:

Output: {{b, c, d}}

I tried DeleteCases command but it does not work. What I we want two letters such as "a" and "c" In that case the output shall be empty. How one handles this?

$\endgroup$
1
  • $\begingroup$ Also consider Select[l, FreeQ[a]] and Select[l, FreeQ[#, c] && MemberQ[#, v] &] ? $\endgroup$
    – user1066
    Jul 26, 2018 at 21:22

1 Answer 1

2
$\begingroup$
Pick[l, FreeQ[a]  /@ l]

{{b, c, d}}

$\endgroup$
3
  • $\begingroup$ Thanks, what if you want do to it for two letters like a and b? (in this case we expect an empty list). In other words can FreeQ be over two letters instead of only one? $\endgroup$
    – Wiliam
    Jul 26, 2018 at 16:17
  • 3
    $\begingroup$ @William Replace a by a|b $\endgroup$
    – Coolwater
    Jul 26, 2018 at 16:19
  • $\begingroup$ Fabulous thanks $\endgroup$
    – Wiliam
    Jul 26, 2018 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.