Usually you’d add a list of integers this way:
You can do it functionally without any loops in different ways:
Using map and a lambda that adds them up
or you can import the add operator as a named function
Ever zipped two lists into a list of tuples?
There’s another more convoluted way if you want to play with “zip”.
Imagine a jacket zipper and the teeth on each side of the zipper is one element on each one of the list.
When you zip the lists a and b, you end up with a list of tuples of matching elements from the given lists.
you could now map a function to add the elements within each tuple on that list.
Notice how we don’t convert to list after zip, we can work directly with the zip iterator, we only convert to list with the final map iterator.
Python 2 & 3 Note:
In Python 2 it’s not necessary to use list(), the map() and zip() methods return lists there. But stay away from Python 2, a lot of projects are now discontinuing support.