[Python-Dev] product()

Nick Coghlan ncoghlan at iinet.net.au
Sun Oct 26 09:39:29 EST 2003


Jeremy Fincher strung bits together to say:
> On Saturday 25 October 2003 11:36 pm, Guido van Rossum wrote:
> 
>>Do we need allfalse() and anytrue() and anyfalse() too?  These can all
>>easily be gotten by judicious use of 'not'.  I think ABC has EACH,
>>SOME and NO (why not all four? who knows).
> 
> There was a recent thread here ("Efficient predicates for the standard 
> library") in which the names "any" and "all" were discussed rather than 
> "anytrue" and "alltrue."  Those are at least their common names in the 
> functional programming languages I know, and it easily sidesteps the 
> confusion that might be caused by having an "anytrue" without an "anyfalse" 
> or an "alltrue" without an "allfalse."

 >>> if all(pred(x) for x in values): pass       # alltrue
 >>> if any(pred(x) for x in values): pass       # anytrue
 >>> if any(not pred(x) for x in values): pass   # anyfalse
 >>> if all(not pred(x) for x in values): pass   # allfalse

The names from the earlier thread do read nicely. . .

Alternately, getting away with just one function:

 >>> if all(pred(x) for x in values): pass          # alltrue
 >>> if not all(not pred(x) for x in values): pass  # anytrue
 >>> if not all(pred(x) for x in values): pass      # anyfalse
 >>> if all(not pred(x) for x in values): pass      # allfalse

I don't know about anyone else, but the double negative required to express 
"any" in terms of "all" hurts my brain. . .

Cheers,
Nick.

-- 
Nick Coghlan           |              Brisbane, Australia
ICQ#: 68854767         |               ncoghlan at email.com
Mobile: 0409 573 268   |   http://www.talkinboutstuff.net
"Let go your prejudices,
               lest they limit your thoughts and actions."




More information about the Python-Dev mailing list