Given the following list
a = [0, 1, 2, 3]
I want to create a new list b, which consists of elements for which the current and next values of a are summed. It will contain 1 less element than a.
Like this:
b = [1, 3, 5]
Here's what I've tried:
b = []
for i in a:
b.append(a[i + 1] + a[i])
The trouble is I keep getting this error:
IndexError: list index out of range
Can somone help me with this?