[Python-ideas] Parametrized any() and all() ?
Tarek Ziadé
tarek at ziade.org
Wed Jan 16 11:30:22 CET 2013
Hello
any() and all() are very useful small functions, and I am wondering if
it could be interesting to have them work
with different operators, by using a callable.
e.g. something like:
import operator
def any(iterable, filter=operator.truth):
for element in iterable:
if filter(element):
return True
return False
For instance I could then us any() to find out if there's a None in the
sequence:
if any(iterable, op=lambda x: x is None):
raise SomeError("There's a none in that list")
Granted, it's easy to do it myself in a small util function - but since
any() and all() are in Python...
Cheers
Tarek
--
Tarek Ziadé · http://ziade.org · @tarek_ziade
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130116/1f62ee59/attachment.html>
More information about the Python-ideas
mailing list