"Collapsing" a list into a list of changes

John Lenton john at grulic.org.ar
Mon Feb 7 13:51:38 EST 2005


On Mon, Feb 07, 2005 at 07:07:10PM +0100, Francis Girard wrote:
> Zut !
> 
> I'm very sorry that there is no good use case for the "reduce" function in 
> Python, like Peter Otten pretends. That's an otherwise very useful tool for 
> many use cases. At least on paper. 
> 
> Python documentation should say "There is no good use case for the reduce 
> function in Python and we don't know why we bother you offering it."

I am guessing you are joking, right? I think Peter exaggerates when he
says that "there will be no good use cases for reduce"; it is very
useful, in writing very compact code when it does exactly what you
want (and you have to go through hoops to do it otherwise). It also
can be the fastest way to do something. For example, the fastest way
to get the factorial of a (small enough) number in pure python is

  factorial = lambda n: reduce(operator.mul, range(1, n+1))

-- 
John Lenton (john at grulic.org.ar) -- Random fortune:
Laugh and the world thinks you're an idiot.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20050207/2686a2ff/attachment.sig>


More information about the Python-list mailing list