Either zip lists, or use numpy :
>>> list1 = [1, 5, 3, 7] >>> list2 = [4, 2, 6, 4] >>> [ab for a,b in zip(list1, list2)] [-3, 3, -3, 3] >>> import numpy as np >>> np.array(list1) - np.array(list2) array([-3, 3, -3, 3])
Remember to return the array to the list as needed.
change
In response to the new requirement that absolute values ββare needed: you can add abs to the list comprehension:
>>> [abs(ab) for a,b in zip(list1, list2)] [3, 3, 3, 3]
and the numpy solution would change to:
>>> map(abs, np.array(list1) - np.array(list2)) [3, 3, 3, 3]
source share