Skip to content
Advertisement

Add SUM of values of two LISTS into new LIST

I have the following two lists:

JavaScript

Now I want to add the items from both of these lists into a new list.

output should be

JavaScript

Advertisement

Answer

The zip function is useful here, used with a list comprehension.

JavaScript

If you have a list of lists (instead of just two lists):

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement