Given 3 nested vectors:
>>> a
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> b
[[10, 20, 30], [40, 50, 60], [70, 80, 90]]
>>> c
[[100, 200, 300], [400, 500, 600], [700, 800, 900]]
I can add these vectors together with a map/sum/zip comprehension like so:
>>> [map(sum,zip(i,j,k)) for i,j,k in zip(a,b,c)]
[[111, 222, 333], [444, 555, 666], [777, 888, 999]]
I've manually expanded this from adding two lists together, but is there a pythonic way to generalize this to handle an arbitrary number of lists?
(Python 2.7 without using external libraries preferred)
itertoolsmay be a useful import