I was wondering which of the following examples is more accepted within the Python community:
1.
return any(host[0].endswith(bot_hosts) for bot_hosts in bot_hosts)
2.
if any(host[0].endswith(bot_hosts) for bot_hosts in bot_hosts):
return True
else:
return False
Or maybe something else?
Please advise.
In your example case:
str.endswithtakes tuple as an argument. Overall, as a design pattern use the first version (check the reasoning @Ben’s answer).That is
any(host[0].endswith(bot_host) for bot_host in bot_hosts)is the same as:Example: