Take for example I have:
list1 = [0, 1, 2, 3]
list2 = [8, 7, 1, 7]
list3 = [1, 2, 3, 4]
combinedlist=[]
How do I ensure that the values will add up together in their respective rows such that the output for combinedlist will be:
[9, 10, 6, 14]
Take for example I have:
list1 = [0, 1, 2, 3]
list2 = [8, 7, 1, 7]
list3 = [1, 2, 3, 4]
combinedlist=[]
How do I ensure that the values will add up together in their respective rows such that the output for combinedlist will be:
[9, 10, 6, 14]
list1 = [0, 1, 2, 3]
list2 = [8, 7, 1, 7]
list3 = [1, 2, 3, 4]
out = [sum(v) for v in zip(list1, list2, list3)]
print(out)
Prints:
[9, 10, 6, 14]
You can try:
list1 = [0, 1, 2, 3]
list2 = [8, 7, 1, 7]
list3 = [1, 2, 3, 4]
combinedlist = [list1[i] + list2[i] + list3[i] for i in range(len(list1))]
print(combinedlist)
Output:
[9, 10, 6, 14]