$ python
Python 2.5.1 (r251:54863, Mar 7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> S = [1, 2, 3, 4]
>>> any(x > 3 for x in S)
True
>>> any(x > 5 for x in S)
False
>>> all(x < 5 for x in S)
True
>>> all(x < 3 for x in S)
False
La cantidad de código que me podría haber ahorrado en esta última semana si hubiese sabido de estas dos maravillosas funciones antes. Ahora toca revisar y modificar.
Visto en The fate of reduce() in Python 3000
Que cosa más curiosa…¿sabes si hay algún equivalente en PHP?
Que yo sepa no… es que esto usa algo llamado list comprehensions y PHP no tiene nada parecido a eso.