[Python-ideas] Parametrized any() and all() ?
Laurens Van Houtven
_ at lvh.cc
Wed Jan 16 11:33:41 CET 2013
Hey Tarek,
I would write that as any(x is None for x in it) -- the example you gave
doesn't really strike me as an improvement over that, although I could see
how many there are cases where it's nicer...
On Wed, Jan 16, 2013 at 11:30 AM, Tarek Ziadé <tarek at ziade.org> wrote:
> 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
>>> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>>
--
cheers
lvh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130116/1373215e/attachment.html>
More information about the Python-ideas
mailing list