[PATCH 1 of 3] util: add any() and all() functions for Python 2.4 compatibility

Greg Ward greg-hg at gerg.ca
Sun Feb 14 15:34:12 CST 2010


On Fri, Feb 12, 2010 at 8:11 PM, Steve Losh <steve at stevelosh.com> wrote:
> +
> +def any(iterable):
> +    for i in iterable:
> +        if i:
> +            return True
> +    return False
> +
> +def all(iterable):
> +    for i in iterable:
> +        if not i:
> +            return False
> +    return True

Shouldn't there be something to use the builtin any() and all() if
they are present?  E.g.

try:
    any, all
except NameError:
    def any...
    def all...

I'm assuming the builtins are written in C and therefore faster than
these implementations.

Greg


More information about the Mercurial-devel mailing list