python - Searching string for different substrings -


i have string. need know if of following substrings appear in string.

so, if have:

thing_name = "visa assessments" 

i've been doing searches with:

any((_ in thing_name _ in ['assessments','kilobyte','international'])) 

i'm going through long list of thing_name items, , don't need filter, exactly, check number of substrings.

is best way this? feels wrong, can't think of more efficient way pull off.

you can try re.search see if faster. along lines of

import re pattern = re.compile('|'.join(['assessments','kilobyte','international'])) ismatch = (pattern.search(thing_name) != none) 

Comments

Popular posts from this blog

Using 'OR' and 'AND' in SQL Server -

c++ - NetBeans Remote Development with additional configuration -

visual studio - TFS will not accept changes I've made to a Java project -