Is reduce() foldl() or foldr()?

Tim Northover T.P.Northover at sms.ed.ac.uk
Sun Jun 7 08:34:26 EDT 2009


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:

> Calling all functional programming fans... is Python's built-in reduce() 
> a left-fold or a right-fold?

I get:

>>> reduce(lambda a, b: a/b, [1.0, 2.0, 3.0])
0.16666666666666666

which looks like a left fold to me.

Tim.



More information about the Python-list mailing list