If you have:
if any(word in sentence for sentence in sentences):
and sentences
is a long list of say, 10,000 sentence-length strings, will any()
iterate through the entire list to determine if any are true, or will it stop looking once a true value is found, since the any()
value is already determined to be true?
If it's truly iterating through the entire list regardless, then of course if would be faster to use a for loop and break once found, as opposed to using any()
, that's why I'm asking.