Fix Python – What is the ‘pythonic’ equivalent to the ‘fold’ function from functional programming?

What is the most idiomatic way to achieve something like the following, in Haskell:
foldl (+) 0 [1,2,3,4,5]
–> 15

Or its equivalent in Ruby:
[1,2,3,4,5].inject(0) {|m,x| m + x}
#> 15

Obviously, Python provides the reduce function, which is an implementation of fold, exactly as above, however, I was told that the ‘pythonic’ way of programming wa….

Fix Python – NameError: name ‘reduce’ is not defined in Python

I’m using Python 3.2. Tried this:
xor = lambda x,y: (x+y)%2
l = reduce(xor, [1,2,3,4])

And got the following error:
l = reduce(xor, [1,2,3,4])
NameError: name ‘reduce’ is not defined

Tried printing reduce into interactive console – got this error:
NameError: name ‘reduce’ is not defined

Is reduce really removed in Python 3.2? If that’s the cas….