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

Steven D'Aprano steve at
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:

but other people say it's a right-fold, e.g.:

"... there is a `foldr` in Haskell that just works like `reduce()`"


"Note that Python already has a variation of foldr, called reduce."

So which is correct? Or is it that different people have different 
definitions of foldl() and foldr()?


More information about the Python-list mailing list