Terrance N. Phillip wrote: > 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?
Here's one way: c = [a_item - b_item for a_item, b_item in zip(a, b)] And another: import operator c = map(operator.sub, a, b) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list