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

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -