I suppose this is a trivial question to many of you, please bear with me.
I have a long list of words, list1. I would like to "remove all words that contain a specific letter, say "o".
list1 = {"world country", "capital", "population", "poppel”, "poppy"} DeleteCases[list1, "o" ∼∼ __] (*does not work*)
I have tried many things and I have looked through many examples to no avail. I have read through Patterns but have not found anything that I can use. Several suggestions here refer to the case where the pattern is a word in the list, like so:
list1 = {"world country", "capital", "population", "popp", "poppy"}
DeleteCases[list1, "popp"]
(* Out: {"world country", "capital", "population", "poppy"} (*works*) *)
But this is not usable, as I need to have a pattern that means "all words that contain the letter "o")
What I am really trying to solve is this: get rid of all words in
list1that contain the letters inlist3, such as:list1 = {"world country", "capital", "population", "popp", "poppy"} list3 = {"o","q"} DeleteCases[list1, list3] (*does not work*) (* My desired output would be {"capital"} *)
StringFreeQ. – Kuba Feb 23 '16 at 14:55Select[list1, StringContainsQ["o"]]– Jason B. Feb 23 '16 at 14:56StringFreeQ! – Jason B. Feb 23 '16 at 14:57Select[list1, Not@*StringContainsQ["o"]]– Jason B. Feb 23 '16 at 14:59Not @*... I dunno what to say. Why not! StringContainsQ["o"], if you're going that way? :P – J. M.'s missing motivation Feb 23 '16 at 15:02- As you receive help, try to give it too, by answering questions in your area of expertise.
- Take the tour and check the faqs!
- When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Feb 23 '16 at 15:06Select[list1, ! StringContainsQ["o"]]didn't return an answer. Using composition allowed it to keep its operator form – Jason B. Feb 23 '16 at 15:07