Jan-29-2023, 02:20 AM
so i have some keywords in a list and i want to check if a string contains any or all of those keywords. E.g
teststring = 'this is a test string it contains apple, orange & banana. Moreover, this i a very long string contact length more than 500k' keywords= ['apple','banana'.'length']i want to do something like,
if (any or all elements in keywords) in teststring: print("Match found")i found a way using any():
if any(ext in teststring for ext in keywords): print("Match found")so the prob. with that is that it can be slow if string is long like in my case contact length > 500k . Is there any better way to do both any or all operations?