for_some(), for_all()?

Michael Hoffman at
Thu Sep 23 12:55:53 CEST 2004

Raymond Hettinger wrote:

> For pure speed, the following is faster and gives short-circuit behavior:
>>>>from itertools import ifilter
>>>>def any(seq, pred=None):
> ...     for elem in ifilter(pred, seq):
> ...         return True
> ...     return False

Nice! I've always found the itertools examples exceptionally useful. Is 
there a reason why they aren't in the standard library? I find myself 
copying and pasting the snippets all the time.
Michael Hoffman

More information about the Python-list mailing list