Adding a Par construct to Python?

Steven D'Aprano steve at
Sun May 17 20:11:57 CEST 2009

On Sun, 17 May 2009 18:24:34 +0200, Diez B. Roggisch wrote:

>> But reduce()? I can't see how you can parallelize reduce(). By its
>> nature, it has to run sequentially: it can't operate on the nth item
>> until it is operated on the (n-1)th item.
> That depends on the operation in question. Addition for example would
> work. 

You'd think so, but you'd be wrong. You can't assume addition is always 

>>> reduce(operator.add, (1.0, 1e57, -1e57))
>>> reduce(operator.add, (1e57, -1e57, 1.0))

> My math-skills are a bit too rusty to qualify the exact nature of
> the operation, commutativity springs to my mind.

And how is reduce() supposed to know whether or not some arbitrary 
function is commutative?


More information about the Python-list mailing list