[Python-ideas] custom predicate for all() & any()

Clint Hepner clint.hepner at gmail.com
Sat Mar 26 12:33:37 EDT 2016


> On 2016 Mar 26 , at 12:30 p, titouan dk <dk.titouan at gmail.com> wrote:
> 
> Hi,
> 
> I was wondering if the builtins functions all() & any() could ever accept a custom predicate:
> 
>     all(iterable, predicate=bool)
>     any(iterable, predicate=bool)

Just map your predicate over the iterable:

    from itertools import imap
    all(imap(bool, iterable))


More information about the Python-ideas mailing list