更新时间:2023-11-13 22:02:58
尝试此测试:
any(substring in string for substring in substring_list)
如果string
中包含任何substring_list
中的子字符串,它将返回True
.
It will return True
if any of the substrings in substring_list
is contained in string
.
Note that there is a Python analogue of Marc Gravell's answer in the linked question:
from itertools import imap
any(imap(s.__contains__, substring_list))
使用生成器表达式的上述版本可能更清晰.
Probably the above version using a generator expression is clearer though.