Parallel arithmetic?

Terrance N. Phillip mediocre_person at
Fri Aug 5 00:37:53 CEST 2005

Given a and b, two equal length lists of integers, I want c to be 
[a1-b1, a2-b2, ... , an-bn]. I can do something like:

c = [0] * len(a)
for ndx, item in enumerate(a):
     c[ndx] = item - b[ndx]

But I'm wondering if there's a better way, perhaps that avoids a loop?


(I seem to recall from my distant past that this sort of thing was dead 
easy with APL... c = a-b, more or less.)


More information about the Python-list mailing list