Python:string包含NOT字符串

Ste*_*ton 1 python

我正在寻找一个执行以下搜索的单行Python表达式:

targets = ['habble', 'norpouf', 'blantom']
entry = "Sorphie porre blantom nushblot"

found=False
for t in targets :
    if t in entry :
        found = True
        break


print ("found" if found else "not found")
Run Code Online (Sandbox Code Playgroud)

这样我们就可以写的东西这样:

print("found" if entry.contains(targets) else "not found")
Run Code Online (Sandbox Code Playgroud)

Aja*_*234 5

你可以使用any:

targets = ['habble', 'norpouf', 'blantom']
entry = "Sorphie porre blantom nushblot"
result = 'found' if any(i in entry for i in targets) else 'not found'
Run Code Online (Sandbox Code Playgroud)