https://programmers.co.kr/learn/courses/30/lessons/70128
νμ΄
# νλ‘κ·Έλλ¨Έμ€ 1λ¨κ³ - λ΄μ
def solution(a,b):
answer = 0
for i in range(len(a)):
answer += a[i] * b[i]
return answer
# νμ΄ 2
def solution(a, b):
return sum([x*y for x, y in zip(a,b)])
μ΄λ² λ¬Έμ λ₯Ό ν΅ν΄ zip λ΄μ₯ ν¨μλ₯Ό μκ² λμλ€.
zip μ¬μ©λ²
>>> numbers = [1, 2, 3]
>>> letters = ["A", "B", "C"]
>>> for pair in zip(numbers, letters):
... print(pair)
...
(1, 'A')
(2, 'B')
(3, 'C')