a few extensions for the itertools

Roberto Bonvallet Roberto.Bonvallet at cern.ch
Mon Nov 20 07:19:42 EST 2006


Mathias Panzenboeck wrote:
>>> forall(predicate, iterable, default=True) -> bool
>>>      Returns True, when for all elements x in iterable
>>>      predicate(x) is True. When the iterable is empty,
>>>      returns default.
>>>
>>>
>>> forany(predicate, iterable, default=False) -> bool
>>>      Returns True, when for any element x in iterable
>>>      predicate(x) is True. When the iterable is empty,
>>>      returns default.
>> 
>> 
>> I vaguely recall plans for all() and any() builtins -- perhaps for Python
>> 2.5?
>> 
> 
> all() and any() don't get predicate functions as arguments.

all(predicate(x) for x in iterable)
any(predicate(x) for x in iterable)

-- 
Roberto Bonvallet



More information about the Python-list mailing list