假设我有两个列表,比如:
list_of_urls = ['https://en.wikipedia.org/wiki/Barack_Obama', 'https://en.wikipedia.org/wiki/President_of_the_United_States', 'google.com']
list_of_blacklisted_urls = ['wikipedia']
如果黑名单url的任何部分在url列表中,如何返回True
?我试过:
for url in list_of_urls:
if any(URL in URLs for URL in list_of_blacklisted_urls):
return True
但我敢肯定这是行不通的。你知道吗
这个怎么样:
你很接近。。。但是
any
函数的工作方式并不像您想象的那样。必须使用嵌套循环。你知道吗举个例子:
然后您可以看到检查数据的结果。你知道吗
相关问题 更多 >
编程相关推荐