Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sum multiple list elements at the same time(python)

How can I sum multiple list elements at the same time?
For example, something like this in Python:

Our lists (input):

[3, 3, 1, 1, 1, 1, 1]
[1, 1, 4, 5, 6, 7, 8]

Output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[4, 4, 5, 6, 7, 8, 9]

Note: we don’t know how many list will be given to us.

>Solution :

This should do the job

l1 = [3, 3, 1, 1, 1, 1, 1]
l2 = [1, 1, 4, 5, 6, 7, 8]

l3 = [sum(t) for t in zip(l1, l2)]
    
print(l3)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading