adding elements of two lists


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. summed = [sum(pair) for pair in zip(listA, listB)]
  2.  
  3. or
  4.  
  5. from operator import add
  6. summed = map(add,listA,listB)
  7.  
  8. or
  9.  
  10. summed = map(sum,zip(listA,listB))

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.