any() and all() Was: Pre-PEP: Dictionary accumulator methods
Raymond Hettinger
vze4rx4y at verizon.net
Sat Mar 19 03:20:42 EST 2005
> > Py2.5 is already going to include any() and all() as builtins. The
> > signature does not include a function, identity or otherwise.
> > Instead, the caller can
> > write a listcomp or genexp that evaluates to True or False:
> >
> > any(x >= 42 for x in data)
[Roose]
> Oh great, I just saw that.
. . .
> But I wish it could be included in Python 2.4.x.
If it is any consolation, the any() can already be expressed somewhat cleanly
and efficiently in Py2.4 with genexps:
True in (x >= 42 for x in data)
The translation for all() is a little less elegant:
False not in (x >= 42 for x in data)
Raymond Hettinger
More information about the Python-list
mailing list