我可以在python中做这样的事情:
l = ['one', 'two', 'three']
if 'some word' in l:
...
这将检查列表中是否存在“某些单词”。但是我可以做相反的事情吗?
l = ['one', 'two', 'three']
if l in 'some one long two phrase three':
...
我必须检查数组中是否有某些单词在字符串中。我可以使用循环来执行此操作,但是这种方式可以包含更多行代码。
if any(word in 'some one long two phrase three' for word in list_):
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句