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

Terry Reedy tjreedy at udel.edu
Sat Mar 26 13:04:43 EDT 2016


On 3/26/2016 12:33 PM, Clint Hepner wrote:
>> On 2016 Mar 26 , at 12:30 p, titouan dk <dk.titouan at gmail.com> wrote:

>> 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))

I agree. In 3.x, which is nearly always the subject of this list,
    map == (2.7) itertools.imap.
So proposed all(iterable, predicate) ==  all(map(predicate, iterable))

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list