python - Sum Parts of Multiple Lists -
this question has answer here:
- element-wise addition of 2 lists? 12 answers
i'm sure there way accomplish want without looping on lists , creating new objects. here have
a = [1, 2, 3, 4] b = [2, 3, 4, 5]
what looking take each set of lists , sum each placeholder output is
[3, 5, 7, 9]
thoughts?
you should use zip function , list comprehension
a = [1, 2, 3, 4] b = [2, 3, 4, 5] [sum(t) t in zip(a,b)]
Comments
Post a Comment