[Python-Dev] product()

Nick Coghlan ncoghlan at iinet.net.au
Mon Oct 27 04:06:35 EST 2003


Jeremy Fincher strung bits together to say:

> On Sunday 26 October 2003 09:39 am, Nick Coghlan wrote:
> 
>> >>> if any(not pred(x) for x in values): pass   # anyfalse
> if not all(pred(x) for x in values): pass

>> >>> if all(not pred(x) for x in values): pass   # allfalse
> 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 :)

I originally wrote them out the way you suggest, but then changed them after I 
added the comment that indicated what each example represented (as the less 
efficient versions more literally match the comments).

Anyway, I suspect those used to the idiom would use the forms you suggest. There 
might be some variation due to the multiple ways of writing the expressions 
(using any/all), but I doubt that would be worse than the confusion created by 
the double negative needed to express either any or all in terms of the other.

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