[Python-ideas] Parametrized any() and all() ? (original) (raw)

INADA Naoki songofacandy at gmail.com
Wed Jan 16 11:37:21 CET 2013


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 <_ at 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 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 · @tarekziade


Python-ideas mailing list Python-ideas at python.org http://mail.python.org/mailman/listinfo/python-ideas

-- cheers lvh


Python-ideas mailing list Python-ideas at python.org http://mail.python.org/mailman/listinfo/python-ideas

-- INADA Naoki <songofacandy at gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130116/21d787f0/attachment.html>



More information about the Python-ideas mailing list