How can I check a string for substrings contained in a list, like in Check if a string contains an element from a list (of strings), but in Python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this test:
It will return
Trueif any of the substrings insubstring_listis contained instring.Note that there is a Python analogue of Marc Gravell’s answer in the linked question:
In Python 3, you can use
mapdirectly instead:Probably the above version using a generator expression is more clear though.