[Python-Dev] product()
Jeremy Fincher
fincher.8 at osu.edu
Sun Oct 26 13:10:27 EST 2003
On Sunday 26 October 2003 09:39 am, Nick Coghlan wrote:
> >>> if all(pred(x) for x in values): pass # alltrue
> >>> if any(pred(x) for x in values): pass # anytrue
Yeah, that does read nicely, which is why I think it's pretty common in FPLs.
> >>> if any(not pred(x) for x in values): pass # anyfalse
I've always expressed this as:
if not all(pred(x) for x in values): pass
> >>> if all(not pred(x) for x in values): pass # allfalse
And this as:
if not any(pred(x) for x in values): pass
It's slightly more efficient (only one negation), and it seems to maintain
better the pseudocode-like aspect that we so much adore in Python :)
Jeremy
More information about the Python-Dev
mailing list