def is_url_interesting(self, url):It's fast because any() shortcircuits the same way "or" does. It's way shorter than the comparable "for" loop. Last of all, I think it's very readable, at least if you're used to reading list comprehensions.
return any(regex.match(url) for regex in self.interesting_url_regexes)
Wednesday, June 04, 2008
Python: any() + generator expression
Here's a nice use of any() with a generator expression: