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")
targets = ['habble', 'norpouf', 'blantom']
entry = "Sorphie porre blantom nushblot"
result = 'found' if any(i in entry for i in targets) else 'not found'
一个问题是标点符号,例如:
^{pr2}$但这仍然有效:
您也可以用另一种方式进行论证,并说
in
可能不是您实际想要的行为,例如:这取决于您的特定问题,但我认为@Ajax1234在这里有优势。在
您可以使用
any
:相关问题 更多 >
编程相关推荐