Favorite non-python language trick?

Christopher Subich spam.csubich+block at block.subich.spam.com
Sun Jul 3 13:20:14 EDT 2005


Steven D'Aprano wrote:
> On Sun, 03 Jul 2005 00:39:19 -0400, Christopher Subich wrote:
>>Personally, I think demanding that it be writable as a sum (or product, 
>>or any, or all) is a false standard -- nobody's claimed that these would 
>>replace all cases of reduce, just the most common ones.
> 
> Er, excuse me, but that is EXACTLY what Devan claimed. 
> 
> Quote: "With the exception of reduce(lambda x,y:x*y, sequence), reduce can be
> replaced with sum, and Guido wants to add a product function."

Okay, then... "not many people have claimed that sum is a universal 
replacement for reduce, only the most common cases."  It's further 
argued that the uncommon cases are more flexible and (again, mostly) 
anywhere from only slightly less readable to significantly more readable 
in for-loop form.

The only corner case that isn't, so far as I know, is when the reduce() 
has no default initial value and the sequence/generator might possibly 
have 0 elements.  But that's a TypeError anyway.



More information about the Python-list mailing list