Suppose I start with a list of strings:
list1 = ['string a','string b','string c','string d']
Using list comprehension, I want to create a second list (list2) that contains strings from list1 if and only if those strings contain certain substrings.
For example, if I wanted to pull only the strings containing 'a', 'b' or 'c', I could write:
list2 = [text for text in list1 if 'a' in text or 'b' in text or 'c' in text]
but this feels clunky. Is there a way to combine my search for the three elements, something like... if ('a' or 'b' or 'c') in text?
If possible, I would like to do this without having to create a list of the substrings, i.e. ['a','b','c'] in a preceding line of code.