-1

I have to test if a list of strings includes at least one element containing a given text (and the text contains quotes). Is it possible in a compact way without defining a new function?

E.g.

# Text to find
text = """This is a text containing 'quotes' and "doublequotes""""

# List to test
test_strings = [
    "This is a text",
    """Wow! This is a text containing 'quotes' and "doublequotes"!!!"""
]

Obviously I can use for loops to do that, but I was looking for something to be run in one line but still readable.

Don
  • 16,928
  • 12
  • 63
  • 101

1 Answers1

-1

I don't feel the quotes should make any difference, but you can just do

strings_with_text = [s for s in test_strings if text in s]
cmxu
  • 954
  • 5
  • 13