I have 2 differently sized lists (a and b) and starting index for a (a_start). I would like to add the lists together, accounting for the fact they are not aligned.
Example inputs and expected output:
a = [1,2]
b = [1,2,3,4]
a_start = 1 # 1st element of a needs to be added to 2nd element of b, etc.
expected result: [1,3,5,4]
Another example:
a = [1,2,3,4]
b = [1,2,3,4]
a_start = 2 # 1st element of a needs to be added to 3rd element of b, etc.
expected result: [1, 2, 4, 6, 3, 4]
My current solution:
[i+j for i,j in zip([0]*a_start + a + [0]*(len(b) - len(a) - a_start), b+[0]*max(0,len(a) + a_start - len(b)))]
What is a more elegant/Pythonic way to do this for any arbitrarily sized lists?