I have a list of integers a
and b
. I want to update the integers in a
such that a[i] = a[i] + b[i]
.
Note: I want to avoid creating a new list. I want to update the existing list.
Currently, I am doing it using a for
loop as shown below.
>>> a = [1, 2, 3, 4, 5]
>>> b = [10, 10, 20, 20, 100]
>>> for i in range(len(a)):
... a[i] += b[i]
...
>>> a
[11, 12, 23, 24, 105]
Can the for
loop be replaced with a single-liner code that is equivalent to it?