(original) (raw)
I think adding this example to docstring and document may help many people.
On Wed, Jan 16, 2013 at 7:33 PM, Laurens Van Houtven <\_@lvh.cc> wrote:
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@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 operatordef 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@python.org
http://mail.python.org/mailman/listinfo/python-ideas
--cheerslvh
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas
INADA Naoki� <songofacandy@gmail.com>