[Python-Dev] Any reason that any()/all() do not take a predicate argument?

2006-04-13 Thread Mikhail Glushenkov
Hi,

sorry if this came up before, but I tried searching the archives and
found nothing.  It would be really nice if new builtin truth functions
in 2.5 took a predicate argument(defaults to bool), so one could
write, for example:

seq = [1,2,3,4,5]
if any(seq, lambda x: x==5):
...

which is clearly more readable than

reduce(seq, lambda x,y: x or y==5, False)

IIRC, something like that is called junctions in Perl 6.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Any reason that any()/all() do not take a predicate argument?

2006-04-15 Thread Mikhail Glushenkov
Andrew Koenig  acm.org> writes:

> How about this?
> 
>   if any(x==5 for x in seq):

Cool! Thank you.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com