python - Sum Parts of Multiple Lists -


this question has answer here:

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

Popular posts from this blog

java - Incorrect order of records in M-M relationship in hibernate -

command line - Use qwinsta in PowerShell ISE -

php - I want to create a website for polls/survey like this http://www.poll-maker.com/ -