There are a few different ways to do that.
The simplest way is using a loop, as mentioned in Richard's comment.
You can also use
operator.add
and the
map
command:
import operator
totalhoursbooked = list(map(operator.add, freehourslist, hoursbookedlist))
See the documentation of
map[
^]:
Quote:
Return an iterator that applies function to every item of iterable, yielding the results.
Then the
list
function transforms this iterator into a list.
You can also use a combination of
list comprehension[
^] and the
zip function[
^].
totalhoursbooked = [a + b for a, b in zip(freehourslist, hoursbookedlist)]
Zip makes an iterator that aggregates elements from each of the iterables passed as arguments. (If you'd convert the
zip
return value to a list, you'd see a list of tuples where each tuple contains an element from freehourslist with the corresponding hoursbookedlist element).