检查是否在另一个字符串中存在多个字符串 [英] Check if multiple strings exist in another string
本文介绍了检查是否在另一个字符串中存在多个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查数组中的所有字符串在另一个字符串是否存在?
How can I check if any of the strings in an array exists in another string?
我爱:
a = ['a', 'b', 'c']
str = "a123"
if a in str:
print "some of the strings found in str"
else:
print "no strings found in str"
这code不起作用,它只是为了显示我想要达到的目标。
That code doesn't work, it's just to show what I want to achieve.
推荐答案
您可以使用 任何
:
if any(x in str for x in a):
同样检查的所有的列表中的字符串被找到,则使用 <强> 所有
代替任何
。
Similarly to check if all the strings from the list are found, use all
instead of any
.
这篇关于检查是否在另一个字符串中存在多个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文