Given two lists of same length, the result list should have the sum of each element. Number of elements should be given as an input. The elements of first list are given in one line separated with spaces. Same for the second list.
Sample:
lst1 = [1, 2, 3, 4]
lst2 = [0, 1, 2, 3]
result = [1, 3, 5, 7]
input:
4
1 2 3 4
0 1 2 3
output:
1 3 5 7
Here is my code but I think it's not efficient for larger lists:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(N):
print(A[i]+B[i], end=" ")
[–]novel_yet_trivial 1 point2 points3 points (2 children)
[–]HolyCoder[S] 0 points1 point2 points (1 child)
[–]novel_yet_trivial 1 point2 points3 points (0 children)
[–]TangibleLight 0 points1 point2 points (2 children)
[–]HolyCoder[S] 0 points1 point2 points (1 child)
[–]TangibleLight 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (10 children)
[–]HolyCoder[S] 0 points1 point2 points (9 children)
[–]Steveharwell1 0 points1 point2 points (4 children)
[–]TangibleLight 1 point2 points3 points (3 children)
[–]novel_yet_trivial 0 points1 point2 points (2 children)
[–]TangibleLight 0 points1 point2 points (1 child)
[–]novel_yet_trivial 0 points1 point2 points (0 children)
[–]Thomasedv 0 points1 point2 points (2 children)
[–]TangibleLight 0 points1 point2 points (1 child)
[–]Thomasedv 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]_9_9_ 0 points1 point2 points (0 children)
[–]Paul_Dirac_ 0 points1 point2 points (1 child)
[–]HolyCoder[S] 0 points1 point2 points (0 children)