Is reduce() foldl() or foldr()?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Jun 7 06:42:20 EDT 2009
Calling all functional programming fans... is Python's built-in reduce()
a left-fold or a right-fold?
Wikipedia says it's a left-fold:
http://en.wikipedia.org/wiki/Fold_(higher-order_function)
but other people say it's a right-fold, e.g.:
"... there is a `foldr` in Haskell that just works like `reduce()`"
http://mail.python.org/pipermail/python-list/2007-November/638647.html
and
"Note that Python already has a variation of foldr, called reduce."
http://blog.sigfpe.com/2008/02/purely-functional-recursive-types-in.html
So which is correct? Or is it that different people have different
definitions of foldl() and foldr()?
--
Steven
More information about the Python-list
mailing list