This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: itertools.any and itertools.all
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, paulcannon
Priority: normal Keywords:

Created on 2006-02-15 20:26 by paulcannon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg54722 - (view) Author: paul cannon (paulcannon) Date: 2006-02-15 20:26
Just a couple very simple "shortcutting" functions that
I find myself needing quite frequently.
"reduce(operator.or_, foo, False)" is all right, but
potentially does a lot more work.


def any(i):
    """Returns true if any element from i is true."""

    for element in i:
        if i:
            return True
    return False


all() would also be nice:


def all(i):
    """Returns true if all elements from i are true."""

    for element in i:
        if not i:
            return False
    return True


..although it /could/ simply be built on any() as "not
any(imap(operator.not_, i))".
msg54723 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-15 20:44
Logged In: YES 
user_id=1188172

These two happen to become builtins in 2.5.
msg54724 - (view) Author: paul cannon (paulcannon) Date: 2006-02-15 21:17
Logged In: YES 
user_id=222090

I love you people.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42907
2006-02-15 20:26:42paulcannoncreate