我正在寻找执行以下搜索的单行 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")
这样我们就可以写一些像这样的东西:
print("found" if entry.contains(targets) else "not found")
请您参考如下方法:
您可以使用任何:
targets = ['habble', 'norpouf', 'blantom']
entry = "Sorphie porre blantom nushblot"
result = 'found' if any(i in entry for i in targets) else 'not found'
