"Collapsing" a list into a list of changes

Francis Girard francis.girard at free.fr
Mon Feb 7 14:58:51 EST 2005


Le lundi 7 Février 2005 19:51, John Lenton a écrit :
> 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? 

Of course I am joking. I meant the exact contrary. Only wanted to show that 
Peter did exaggerate. Thank you for citing me with the full context.

> 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))

Great. 

Regards

Francis Girard




More information about the Python-list mailing list